mirror of
https://e.coding.net/circlecloud/RocketJump.git
synced 2025-11-24 23:56:06 +00:00
118
src/main/java/cn/citycraft/RocketJump/Listen.java
Normal file
118
src/main/java/cn/citycraft/RocketJump/Listen.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package cn.citycraft.RocketJump;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
|
||||
/**
|
||||
* Created by a08381 on 15-3-28.
|
||||
*/
|
||||
public class Listen implements Listener {
|
||||
RocketJump plugin;
|
||||
List<String> fall = new ArrayList<String>();
|
||||
List<String> efc = new ArrayList<String>();
|
||||
int trng;
|
||||
|
||||
public Listen(RocketJump main) {
|
||||
plugin = main;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void MoveEvent(PlayerMoveEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (efc.contains(p.getName())) {
|
||||
trng -= 1;
|
||||
pEffect(p.getLocation(), trng);
|
||||
}
|
||||
if (p.getLocation().add(0, -1, 0).getBlock().getType() != (Material.AIR))
|
||||
if (plugin.Dante.contains(p.getName())) {
|
||||
p.setAllowFlight(true);
|
||||
if (fall.contains(p.getName()))
|
||||
fall.remove(p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void ToggleFlightEvent(PlayerToggleFlightEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
if (plugin.Dante.contains(p.getName())) {
|
||||
if (p.getLocation().add(0, -1, 0).getBlock().getType() == (Material.AIR)
|
||||
&& p.getLocation().add(0, -2, 0).getBlock().getType() == (Material.AIR)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!p.isFlying()) {
|
||||
e.setCancelled(true);
|
||||
pEffect(p.getLocation(), 80);
|
||||
p.setVelocity(p.getVelocity().setY(1));
|
||||
p.setAllowFlight(false);
|
||||
plugin.getServer().getScheduler()
|
||||
.runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (p.isOnline()) {
|
||||
p.setVelocity(p.getVelocity().setY(10));
|
||||
final String name = p.getName();
|
||||
efcadd(name);
|
||||
add(name);
|
||||
plugin.getServer()
|
||||
.getScheduler()
|
||||
.runTaskLaterAsynchronously(plugin,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (efc.contains(name))
|
||||
efc.remove(name);
|
||||
}
|
||||
}, 30);
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
trng = 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pEffect(Location loc, int range) {
|
||||
int i;
|
||||
if (range < 2)
|
||||
range = 2;
|
||||
for (i = 0; i < range; i++) {
|
||||
loc.getWorld().playEffect(loc, Effect.LAVA_POP, 10, 100);
|
||||
loc.getWorld().playEffect(loc, Effect.PORTAL, 10, 100);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFallDamage(EntityDamageEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Player p = (Player) e.getEntity();
|
||||
if (e.getCause() == DamageCause.FALL) {
|
||||
if (fall.contains(p.getName())) {
|
||||
fall.remove(p.getName());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void add(String p) {
|
||||
if (!fall.contains(p))
|
||||
fall.add(p);
|
||||
}
|
||||
|
||||
public void efcadd(String p) {
|
||||
if (!efc.contains(p))
|
||||
efc.add(p);
|
||||
}
|
||||
}
|
||||
53
src/main/java/cn/citycraft/RocketJump/RocketJump.java
Normal file
53
src/main/java/cn/citycraft/RocketJump/RocketJump.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package cn.citycraft.RocketJump;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
/**
|
||||
* Created by a08381 on 15-3-28.
|
||||
*/
|
||||
public class RocketJump extends JavaPlugin {
|
||||
|
||||
List<String> Dante = new ArrayList<String>() ;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String string,
|
||||
String[] args) {
|
||||
Player p = (Player) sender;
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("on")) {
|
||||
this.Dante.add(p.getName());
|
||||
sender.sendMessage("§6[RocketJump]§a火箭跳跃已开启,双击空格启动。。。");
|
||||
p.setAllowFlight(true);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("off")) {
|
||||
this.Dante.remove(p.getName());
|
||||
sender.sendMessage("§6[RocketJump]§4已关闭...");
|
||||
if (p.getGameMode() == GameMode.SURVIVAL) {
|
||||
p.setAllowFlight(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info( "§4RocketJump已卸载...");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getServer().getPluginManager().registerEvents(new Listen(this), this);
|
||||
getLogger().info("§aRocketJump已加载...");
|
||||
}
|
||||
|
||||
}
|
||||
112
src/main/java/cn/citycraft/RocketJump/utils/VersionChecker.java
Normal file
112
src/main/java/cn/citycraft/RocketJump/utils/VersionChecker.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package cn.citycraft.RocketJump.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
/**
|
||||
* 自动更新类
|
||||
*
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月14日下午4:01:15
|
||||
*/
|
||||
public class VersionChecker implements Listener {
|
||||
Plugin plugin;
|
||||
public String checkurl = "https://coding.net/u/502647092/p/%s/git/raw/%s/src/plugin.yml";
|
||||
public String branch = "master";
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
* - 插件
|
||||
*/
|
||||
public VersionChecker(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.versioncheck(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
* - 插件
|
||||
* @param branch
|
||||
* - 分支名称
|
||||
*/
|
||||
public VersionChecker(Plugin plugin, String branch) {
|
||||
this.plugin = plugin;
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
this.checkurl = branch;
|
||||
this.versioncheck(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件更新链接
|
||||
*
|
||||
* @param pluginName
|
||||
* - 插件名称
|
||||
* @param branch
|
||||
* - 插件分支
|
||||
* @return 更新链接
|
||||
*/
|
||||
public String getCheckUrl(String pluginName, String branch) {
|
||||
return String.format(checkurl, pluginName, branch);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
if (e.getPlayer().isOp()) {
|
||||
this.versioncheck(e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始更新
|
||||
*
|
||||
* @param player
|
||||
* - 获取更新的玩家(null则默认为控制台)
|
||||
*/
|
||||
public void versioncheck(final Player player) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String readURL = getCheckUrl(plugin.getName(), branch);
|
||||
FileConfiguration config;
|
||||
String currentVersion = plugin.getDescription().getVersion();
|
||||
try {
|
||||
URL url = new URL(readURL);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), Charsets.UTF_8));
|
||||
config = YamlConfiguration.loadConfiguration(br);
|
||||
String newVersion = config.getString("version");
|
||||
br.close();
|
||||
if (!newVersion.equals(currentVersion)) {
|
||||
String[] msg = new String[] {
|
||||
ChatColor.GREEN + plugin.getName() + " 插件最新版本 v" + newVersion,
|
||||
ChatColor.RED + "服务器运行版本: v" + currentVersion,
|
||||
ChatColor.GOLD + "插件更新网站: " + ChatColor.BLUE + plugin.getDescription().getWebsite()
|
||||
};
|
||||
if (player != null) {
|
||||
player.sendMessage(msg);
|
||||
} else {
|
||||
plugin.getServer().getConsoleSender().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("版本更新检查失败!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
15
src/main/resources/plugin.yml
Normal file
15
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/
|
||||
version: ${project.version}
|
||||
authors: [喵♂呜]
|
||||
commands:
|
||||
rj:
|
||||
description: RocketJump插件
|
||||
usage: 使用/rj <on|off> 切换RocketJump!
|
||||
permission: rj.use
|
||||
permission-message: §c你没有此命令的权限!
|
||||
permissions:
|
||||
rj.use:
|
||||
default: op
|
||||
Reference in New Issue
Block a user