1
0
mirror of https://e.coding.net/circlecloud/SimpleEssential.git synced 2025-01-07 12:28:56 +00:00
+ /suicide command with a not working death message
+ Buggy /hat
+ A function to register controllers likes register events and commands
* Moved command utility to a single package cn.citycraft/SimpleEssential/command/utils

! Sometimes language file dosn't working and I don't know what happened
! Hat cannot judge is a air on hand... I tried to if but not working!
! Death message for suicide is not working!

# I know that's all my fault and please fix them!
# Symbols: + Add - Remove x Fixed ! Bug # Description * Change
# Wish you know!
This commit is contained in:
代小呆 2015-08-16 14:19:11 +08:00
parent 1c529d697c
commit 1ff9008275
11 changed files with 420 additions and 274 deletions

View File

@ -1,7 +1,8 @@
package cn.citycraft.SimpleEssential;
/** /**
* *
*/ */
package cn.citycraft.SimpleEssential;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -14,18 +15,20 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.SimpleEssential.command.CommandBack; import cn.citycraft.SimpleEssential.command.CommandBack;
import cn.citycraft.SimpleEssential.command.CommandHat;
import cn.citycraft.SimpleEssential.command.CommandHome; import cn.citycraft.SimpleEssential.command.CommandHome;
import cn.citycraft.SimpleEssential.command.CommandSetHome; import cn.citycraft.SimpleEssential.command.CommandSetHome;
import cn.citycraft.SimpleEssential.command.CommandSuicide;
import cn.citycraft.SimpleEssential.command.CommandTop; import cn.citycraft.SimpleEssential.command.CommandTop;
import cn.citycraft.SimpleEssential.command.CommandTpa; import cn.citycraft.SimpleEssential.command.CommandTpa;
import cn.citycraft.SimpleEssential.command.CommandTpaccept; import cn.citycraft.SimpleEssential.command.CommandTpaccept;
import cn.citycraft.SimpleEssential.command.CommandTpdeny; import cn.citycraft.SimpleEssential.command.CommandTpdeny;
import cn.citycraft.SimpleEssential.command.CommandTphere; import cn.citycraft.SimpleEssential.command.CommandTphere;
import cn.citycraft.SimpleEssential.command.SimpleEssentialCommand; import cn.citycraft.SimpleEssential.command.SimpleEssentialCommand;
import cn.citycraft.SimpleEssential.command.utils.teleport.TeleportControl;
import cn.citycraft.SimpleEssential.config.Config; import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language; import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.listen.PlayerLocationListen; import cn.citycraft.SimpleEssential.listeners.TeleportDeathBackListener;
import cn.citycraft.SimpleEssential.teleport.TeleportControl;
import cn.citycraft.SimpleEssential.utils.VersionChecker; import cn.citycraft.SimpleEssential.utils.VersionChecker;
/** /**
@ -36,7 +39,7 @@ import cn.citycraft.SimpleEssential.utils.VersionChecker;
public class SimpleEssential extends JavaPlugin { public class SimpleEssential extends JavaPlugin {
/** /**
* 传送控制 * 控制
*/ */
public TeleportControl tpcontrol; public TeleportControl tpcontrol;
/** /**
@ -75,9 +78,9 @@ public class SimpleEssential extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
tpcontrol = new TeleportControl(this);
this.registerCommands(); this.registerCommands();
this.registerEvents(); this.registerEvents();
this.registerControllers();
new VersionChecker(this); new VersionChecker(this);
} }
@ -85,7 +88,13 @@ public class SimpleEssential extends JavaPlugin {
* 注册事件 * 注册事件
*/ */
private void registerEvents() { private void registerEvents() {
registerEvent(new PlayerLocationListen(this)); registerEvent(new TeleportDeathBackListener(this));
}
/**
* 初始化控制器
*/
private void registerControllers(){
tpcontrol = new TeleportControl(this);
} }
@Override @Override
@ -107,7 +116,9 @@ public class SimpleEssential extends JavaPlugin {
registerCommand(new CommandBack(this)); registerCommand(new CommandBack(this));
registerCommand(new CommandSetHome(this)); registerCommand(new CommandSetHome(this));
registerCommand(new CommandHome(this)); registerCommand(new CommandHome(this));
registerCommand(new CommandSuicide(this));
registerCommand(new CommandHat(this));
} }
/** /**

View File

@ -0,0 +1,60 @@
package cn.citycraft.SimpleEssential.command;
import org.bukkit.Material;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Language;
/**
*@Author 代小呆 created in 2015年8月16日下午1:44:22
*/
public class CommandHat extends SimpleEssentialCommand{
@SuppressWarnings("unused")
private SimpleEssential plugin;
public CommandHat(SimpleEssential se) {
super("hat","sehat");
this.plugin = se;
}
@Override
public String getPossibleArguments() {
return "";
}
@Override
public int getMinimumArguments() {
return 0;
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player p = (Player)sender;
if(p.getItemInHand() == null){
sender.sendMessage(Language.getMessage("Hat.empty"));
return;
}else{
ItemStack hand = p.getItemInHand();
p.setItemInHand(null);
ItemStack helmet = p.getInventory().getHelmet();
if(!(helmet == null)){
p.getInventory().addItem(helmet);
}
p.getInventory().setHelmet(hand);
sender.sendMessage(Language.getMessage("Hat.enjoy"));
}
}
@Override
public boolean isOnlyPlayerExecutable() {
return true;
}
}

View File

@ -0,0 +1,61 @@
package cn.citycraft.SimpleEssential.command;
import java.util.Arrays;
import cn.citycraft.SimpleEssential.SimpleEssential;
import org.bukkit.Effect;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
//import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.event.entity.PlayerDeathEvent;
//import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.utils.EffectUtil;
//import cn.citycraft.SimpleEssential.utils.Randomer;
/**
* 自杀命令
*@Author 代小呆 created in 2015年8月14日下午4:24:19
*/
public class CommandSuicide extends SimpleEssentialCommand{
private SimpleEssential plugin;
public CommandSuicide(SimpleEssential main) {
super("suicide", new String[]{"sesuicide","sd"});
this.plugin = main;
}
@Override
public String getPossibleArguments() {
return "";
}
@Override
public int getMinimumArguments() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
Player p = (Player)sender;
EffectUtil.run(p.getLocation(), 10, Effect.POTION_BREAK);
PlayerDeathEvent pd = new PlayerDeathEvent(p,Arrays.asList(p.getInventory().getContents()),
(int) Math.floor(p.getExp()),p.getName() + "自杀了");
plugin.getServer().getPluginManager().callEvent(pd);
// plugin.getServer().broadcastMessage(Language.getMessage("Suicide.suicide",sender.getName()));
p.setHealth(0);
}
@Override
public boolean isOnlyPlayerExecutable() {
return true;
}
}

View File

@ -9,8 +9,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.command.utils.teleport.TeleportType;
import cn.citycraft.SimpleEssential.config.Language; import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.teleport.TeleportType;
/** /**
* 玩家传送命令 * 玩家传送命令

View File

@ -9,8 +9,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.command.utils.teleport.TeleportType;
import cn.citycraft.SimpleEssential.config.Language; import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.teleport.TeleportType;
/** /**
* 传送到玩家命令 * 传送到玩家命令

View File

@ -1,183 +1,183 @@
/** /**
* *
*/ */
package cn.citycraft.SimpleEssential.teleport; package cn.citycraft.SimpleEssential.command.utils.teleport;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.SimpleEssential;
import cn.citycraft.SimpleEssential.config.Config; import cn.citycraft.SimpleEssential.config.Config;
import cn.citycraft.SimpleEssential.config.Language; import cn.citycraft.SimpleEssential.config.Language;
import cn.citycraft.SimpleEssential.utils.EffectUtil; import cn.citycraft.SimpleEssential.utils.EffectUtil;
/** /**
* @author 蒋天蓓 2015年8月12日下午2:26:10 传送控制类 * @author 蒋天蓓 2015年8月12日下午2:26:10 传送控制类
*/ */
public class TeleportControl { public class TeleportControl {
protected HashMap<Player, TeleportInfo> teleportList = new HashMap<Player, TeleportInfo>(); protected HashMap<Player, TeleportInfo> teleportList = new HashMap<Player, TeleportInfo>();
protected HashMap<Player, Location> lastlocList = new HashMap<Player, Location>(); protected HashMap<Player, Location> lastlocList = new HashMap<Player, Location>();
private SimpleEssential plugin; private SimpleEssential plugin;
private int TpDelay = Config.getInstance().getInt("Teleport.delay", 3); private int TpDelay = Config.getInstance().getInt("Teleport.delay", 3);
public TeleportControl(SimpleEssential plugin) { public TeleportControl(SimpleEssential plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
/** /**
* 玩家接受传送请求 * 玩家接受传送请求
* *
* @param player * @param player
* - 执行的玩家 * - 执行的玩家
*/ */
public void accept(Player player) { public void accept(Player player) {
TeleportInfo ti = teleportList.remove(player); TeleportInfo ti = teleportList.remove(player);
if (ti != null) { if (ti != null) {
Player target = ti.getTarget(); Player target = ti.getTarget();
Location loc = null; Location loc = null;
if (!target.isOnline()) { if (!target.isOnline()) {
player.sendMessage(Language.getMessage("Teleport.offline")); player.sendMessage(Language.getMessage("Teleport.offline"));
return; return;
} }
if (ti.getTptype() == TeleportType.TPA) { if (ti.getTptype() == TeleportType.TPA) {
target = ti.getTarget(); target = ti.getTarget();
loc = player.getLocation(); loc = player.getLocation();
} else { } else {
target = player; target = player;
loc = ti.getTarget().getLocation(); loc = ti.getTarget().getLocation();
} }
player.sendMessage(Language.getMessage("Teleport.accept")); player.sendMessage(Language.getMessage("Teleport.accept"));
target.sendMessage(Language.getMessage("Teleport.acceptfrom")); target.sendMessage(Language.getMessage("Teleport.acceptfrom"));
magicTeleport(target, loc, TpDelay); magicTeleport(target, loc, TpDelay);
return; return;
} }
player.sendMessage(Language.getMessage("Teleport.none")); player.sendMessage(Language.getMessage("Teleport.none"));
} }
/** /**
* 添加传送请求到传送列表 * 添加传送请求到传送列表
* *
* @param player * @param player
* - 发出请求的玩家 * - 发出请求的玩家
* @param target * @param target
* - 目标玩家 * - 目标玩家
* @param tptype * @param tptype
* - 传送类型 * - 传送类型
*/ */
public void addtp(Player player, Player target, TeleportType tptype) { public void addtp(Player player, Player target, TeleportType tptype) {
teleportList.put(target, new TeleportInfo(player, tptype)); teleportList.put(target, new TeleportInfo(player, tptype));
} }
/** /**
* 玩家返回上次传送的地点 * 玩家返回上次传送的地点
* *
* @param player * @param player
* - 被传送的玩家 * - 被传送的玩家
*/ */
public void back(Player player) { public void back(Player player) {
Location loc = lastlocList.get(player); Location loc = lastlocList.get(player);
if (loc != null) { if (loc != null) {
magicTeleport(player, loc, 3); magicTeleport(player, loc, 3);
} else { } else {
player.sendMessage(Language.getMessage("Teleport.nobackloc")); player.sendMessage(Language.getMessage("Teleport.nobackloc"));
} }
} }
/** /**
* 玩家拒绝传送请求 * 玩家拒绝传送请求
* *
* @param player * @param player
* - 执行的玩家 * - 执行的玩家
*/ */
public void deny(Player player) { public void deny(Player player) {
TeleportInfo ti = teleportList.remove(player); TeleportInfo ti = teleportList.remove(player);
if (ti != null) { if (ti != null) {
Player target = ti.getTarget(); Player target = ti.getTarget();
if (target.isOnline()) { if (target.isOnline()) {
player.sendMessage(Language.getMessage("Teleport.deny")); player.sendMessage(Language.getMessage("Teleport.deny"));
target.sendMessage(Language.getMessage("Teleport.denyfrom")); target.sendMessage(Language.getMessage("Teleport.denyfrom"));
} }
return; return;
} }
player.sendMessage(Language.getMessage("Teleport.none")); player.sendMessage(Language.getMessage("Teleport.none"));
} }
/** /**
* 魔法传送 * 魔法传送
* *
* @param player * @param player
* - 被传送的玩家 * - 被传送的玩家
* @param loc * @param loc
* - 传送的地点 * - 传送的地点
*/ */
public void magicTeleport(final Player player, final Location loc) { public void magicTeleport(final Player player, final Location loc) {
magicTeleport(player, loc, TpDelay); magicTeleport(player, loc, TpDelay);
} }
/** /**
* 魔法传送 * 魔法传送
* *
* @param player * @param player
* - 被传送的玩家 * - 被传送的玩家
* @param loc * @param loc
* - 传送的地点 * - 传送的地点
* @param delay * @param delay
* - 传送延时 * - 传送延时
*/ */
public void magicTeleport(final Player player, final Location loc, final int delay) { public void magicTeleport(final Player player, final Location loc, final int delay) {
int petime = delay * 20 + 10; int petime = delay * 20 + 10;
setLastloc(player, player.getLocation()); setLastloc(player, player.getLocation());
player.sendMessage(Language.getMessage("Teleport.tp", delay, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ())); player.sendMessage(Language.getMessage("Teleport.tp", delay, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ()));
List<PotionEffect> pe = new ArrayList<PotionEffect>(); List<PotionEffect> pe = new ArrayList<PotionEffect>();
pe.add(new PotionEffect(PotionEffectType.SLOW, petime, 255)); pe.add(new PotionEffect(PotionEffectType.SLOW, petime, 255));
pe.add(new PotionEffect(PotionEffectType.CONFUSION, petime, 255)); pe.add(new PotionEffect(PotionEffectType.CONFUSION, petime, 255));
player.addPotionEffects(pe); player.addPotionEffects(pe);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
long timeoutmark = System.currentTimeMillis() + delay * 1000; long timeoutmark = System.currentTimeMillis() + delay * 1000;
long lrng = 0; long lrng = 0;
@Override @Override
public void run() { public void run() {
while (System.currentTimeMillis() < timeoutmark) { while (System.currentTimeMillis() < timeoutmark) {
if (player.isOnline()) { if (player.isOnline()) {
EffectUtil.run(player.getLocation(), lrng, Effect.MOBSPAWNER_FLAMES, Effect.PORTAL); EffectUtil.run(player.getLocation(), lrng, Effect.MOBSPAWNER_FLAMES, Effect.PORTAL);
} }
lrng++; lrng++;
try { try {
Thread.sleep(128); Thread.sleep(128);
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }
}); });
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
if (player.isOnline()) { if (player.isOnline()) {
player.teleport(loc); player.teleport(loc);
} }
} }
}, delay * 20); }, delay * 20);
} }
/** /**
* 设置最后的地址数据 * 设置最后的地址数据
* *
* @param player * @param player
* - 玩家 * - 玩家
* @param loc * @param loc
* - 地点 * - 地点
*/ */
public void setLastloc(Player player, Location loc) { public void setLastloc(Player player, Location loc) {
lastlocList.put(player, loc); lastlocList.put(player, loc);
} }
} }

View File

@ -1,31 +1,31 @@
/** /**
* *
*/ */
package cn.citycraft.SimpleEssential.teleport; package cn.citycraft.SimpleEssential.command.utils.teleport;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
* 玩家传送记录 * 玩家传送记录
* *
* @author 蒋天蓓 * @author 蒋天蓓
* 2015年8月12日下午2:56:25 * 2015年8月12日下午2:56:25
* *
*/ */
public class TeleportInfo { public class TeleportInfo {
protected TeleportType tptype; protected TeleportType tptype;
protected Player target; protected Player target;
public TeleportInfo(Player target, TeleportType tptype) { public TeleportInfo(Player target, TeleportType tptype) {
this.target = target; this.target = target;
this.tptype = tptype; this.tptype = tptype;
} }
public TeleportType getTptype() { public TeleportType getTptype() {
return tptype; return tptype;
} }
public Player getTarget() { public Player getTarget() {
return target; return target;
} }
} }

View File

@ -1,15 +1,15 @@
/** /**
* *
*/ */
package cn.citycraft.SimpleEssential.teleport; package cn.citycraft.SimpleEssential.command.utils.teleport;
/** /**
* 传送类型枚举 * 传送类型枚举
* *
* @author 蒋天蓓 * @author 蒋天蓓
* 2015年8月12日下午2:56:59 * 2015年8月12日下午2:56:59
* *
*/ */
public enum TeleportType { public enum TeleportType {
TPA, TPH TPA, TPH
} }

View File

@ -1,35 +1,35 @@
/** /**
* *
*/ */
package cn.citycraft.SimpleEssential.listen; package cn.citycraft.SimpleEssential.listeners;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import cn.citycraft.SimpleEssential.SimpleEssential; import cn.citycraft.SimpleEssential.SimpleEssential;
/** /**
* 玩家传送点记录监听 * 玩家传送点记录监听
* *
* @author 蒋天蓓 * @author 蒋天蓓
* 2015年8月12日下午8:19:33 * 2015年8月12日下午8:19:33
* *
*/ */
public class PlayerLocationListen implements Listener { public class TeleportDeathBackListener implements Listener {
SimpleEssential plugin; SimpleEssential plugin;
public PlayerLocationListen(SimpleEssential main) { public TeleportDeathBackListener(SimpleEssential main) {
this.plugin = main; this.plugin = main;
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent e) { public void onPlayerDeath(PlayerDeathEvent e) {
Player player = e.getEntity(); Player player = e.getEntity();
Location loc = player.getLocation(); Location loc = player.getLocation();
plugin.tpcontrol.setLastloc(player, loc); plugin.tpcontrol.setLastloc(player, loc);
} }
} }

View File

@ -23,4 +23,11 @@ Teleport:
tphere: '§b玩家: %s§b请求你传送到他那里!' tphere: '§b玩家: %s§b请求你传送到他那里!'
tpaccept: '§a输入命令/tpaccept 或 /tpok 接受传送' tpaccept: '§a输入命令/tpaccept 或 /tpok 接受传送'
tpdeny: '§c输入命令/tpdeny 或 /tpno 拒绝传送' tpdeny: '§c输入命令/tpdeny 或 /tpno 拒绝传送'
nobackloc: '§c未找到可以Back的地点!' nobackloc: '§c未找到可以Back的地点!'
#自杀
Suicide:
suicide: '玩家 %s 自刎了!'
#帽子
Hat:
empty: '§c看上去你手上什么都没有啊'
enjoy: '§2享受你的新帽子吧'

View File

@ -63,6 +63,12 @@ commands:
usage: §b使用/suicide结束自己的生命! usage: §b使用/suicide结束自己的生命!
permission: se.suicide permission: se.suicide
permission-message: §c你没有 <permission> 的权限来执行此命令! permission-message: §c你没有 <permission> 的权限来执行此命令!
hat:
description: 戴上手中的物品到脑袋上
aliases: [sehat]
usage: §b使用/hat戴上一款亮闪闪的帽子
permission: se.hat
permission-message: §c你没有 <permission> 的权限来执行此命令!
permissions: permissions:
se.*: se.*:
description: 简单基础插件所有权限! description: 简单基础插件所有权限!
@ -81,4 +87,5 @@ permissions:
se.sethome: true se.sethome: true
se.home: true se.home: true
se.suicide: true se.suicide: true
se.hat: true