mirror of
https://e.coding.net/circlecloud/CarryEnchantBench.git
synced 2025-11-26 00:06:02 +00:00
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.CarryEnchantBench;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.CarryEnchantBench.inventory.InventoryControl;
|
||||
import cn.citycraft.CarryEnchantBench.listen.PlayerInventoryViewListen;
|
||||
|
||||
/**
|
||||
* @author 蒋天蓓
|
||||
* 2015年8月24日下午3:48:42
|
||||
* TODO
|
||||
*/
|
||||
public class CarryEnchantBench extends JavaPlugin {
|
||||
|
||||
public InventoryControl invcontrol;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("控制台吃饱了撑着用毛线附魔台啊");
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
invcontrol.openEnchantBench(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
invcontrol = new InventoryControl(this);
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerInventoryViewListen(this), this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.CarryEnchantBench.inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cn.citycraft.CarryEnchantBench.CarryEnchantBench;
|
||||
|
||||
/**
|
||||
* @author 蒋天蓓
|
||||
*
|
||||
*/
|
||||
public class InventoryControl {
|
||||
CarryEnchantBench plugin;
|
||||
HashMap<String, Location> enchantbench = new HashMap<String, Location>();
|
||||
|
||||
public InventoryControl(CarryEnchantBench main) {
|
||||
this.plugin = main;
|
||||
}
|
||||
|
||||
public void clearAllEnchantBench() {
|
||||
for (Entry<String, Location> item : enchantbench.entrySet()) {
|
||||
setRange(item.getValue(), Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearEnchantBench(Player player) {
|
||||
if (!isOpenEnchantBench(player))
|
||||
return;
|
||||
Location loc = enchantbench.get(player.getName());
|
||||
setRange(loc, Material.AIR);
|
||||
loc.getBlock().setType(Material.AIR);
|
||||
}
|
||||
|
||||
public boolean isOpenEnchantBench(Player player) {
|
||||
return enchantbench.containsKey(player.getName());
|
||||
}
|
||||
|
||||
public void openEnchantBench(Player player) {
|
||||
Location loc = player.getLocation();
|
||||
loc.setY(250);
|
||||
setEnchatRange(loc);
|
||||
player.openEnchanting(loc, true);
|
||||
enchantbench.put(player.getName(), loc);
|
||||
};
|
||||
|
||||
protected void setBlock(Location loc, int x, int y, int z, Material ma) {
|
||||
new Location(loc.getWorld(), loc.getBlockX() + x, loc.getBlockY() + y, loc.getBlockZ() + z).getBlock().setType(ma);
|
||||
}
|
||||
|
||||
protected void setEnchatRange(Location loc) {
|
||||
setRange(loc, Material.BOOKSHELF);
|
||||
loc.getBlock().setType(Material.ENCHANTMENT_TABLE);
|
||||
}
|
||||
|
||||
protected void setRange(Location loc, Material ma) {
|
||||
for (int i = -2; i < 3; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
for (int k = -2; k < 3; k++) {
|
||||
if (!((i * k == 0) || (i * k * i * k == 1))) {
|
||||
setBlock(loc, i, j, k, ma);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package cn.citycraft.CarryEnchantBench.listen;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import cn.citycraft.CarryEnchantBench.CarryEnchantBench;
|
||||
|
||||
/**
|
||||
* 玩家随身附魔台记录监听
|
||||
*
|
||||
* @author 蒋天蓓 2015年8月12日下午8:19:33
|
||||
*
|
||||
*/
|
||||
public class PlayerInventoryViewListen implements Listener {
|
||||
CarryEnchantBench plugin;
|
||||
|
||||
public PlayerInventoryViewListen(CarryEnchantBench main) {
|
||||
this.plugin = main;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
if (!(e.getPlayer() instanceof Player))
|
||||
return;
|
||||
Player player = (Player) e.getPlayer();
|
||||
Inventory inv = e.getInventory();
|
||||
if (inv.getType() == InventoryType.ENCHANTING) {
|
||||
plugin.invcontrol.clearEnchantBench(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/main/resources/plugin.yml
Normal file
12
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: ${project.artifactId}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/
|
||||
version: ${project.version}
|
||||
authors: [喵♂呜]
|
||||
commands:
|
||||
ceb:
|
||||
description: 随身附魔台
|
||||
usage: §6使用§a/ceb §6打开附魔台!
|
||||
permission: ceb.use
|
||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||
|
||||
Reference in New Issue
Block a user