mirror of
https://e.coding.net/circlecloud/CarryEnchantBench.git
synced 2024-10-31 11:18:48 +00:00
init Custom Version...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
b85f3a33bc
commit
7017f2761b
@ -3,37 +3,89 @@
|
||||
*/
|
||||
package cn.citycraft.CarryEnchantBench;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
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;
|
||||
public class CarryEnchantBench extends JavaPlugin implements Listener {
|
||||
Location loc = null;
|
||||
List<String> setList = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("控制台吃饱了撑着用毛线附魔台啊");
|
||||
sender.sendMessage("§c控制台吃饱了撑着用毛线附魔台啊");
|
||||
}
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
Player p = (Player) sender;
|
||||
invcontrol.openEnchantBench(p);
|
||||
if (loc.getBlock().getType() != Material.ENCHANTMENT_TABLE) {
|
||||
p.sendMessage("§c管理员尚未配置随身附魔台的位置或附魔台被破坏!");
|
||||
}
|
||||
p.openEnchanting(loc, true);
|
||||
p.sendMessage("§a已打开随身附魔台!");
|
||||
return true;
|
||||
case 1:
|
||||
if (args[0].equalsIgnoreCase("set")) {
|
||||
if (sender.hasPermission("ceb.set")) {
|
||||
if (!setList.contains(sender.getName())) {
|
||||
setList.add(sender.getName());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(PlayerInteractEvent e) {
|
||||
Block b = e.getClickedBlock();
|
||||
Player p = e.getPlayer();
|
||||
if (setList.contains(p.getName())) {
|
||||
if (b.getType() == Material.ENCHANTMENT_TABLE) {
|
||||
loc = b.getLocation();
|
||||
this.getConfig().set("Location.World", loc.getWorld().getName());
|
||||
this.getConfig().set("Location.X", loc.getBlockX());
|
||||
this.getConfig().set("Location.Y", loc.getBlockY());
|
||||
this.getConfig().set("Location.Z", loc.getBlockZ());
|
||||
this.saveConfig();
|
||||
p.sendMessage("§a已成功配置随身附魔台的位置 §c请勿破坏 负责将会影响插件工作!");
|
||||
} else {
|
||||
p.sendMessage("§c请点击附魔台配置随身附魔台位置!");
|
||||
}
|
||||
setList.remove(p.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
invcontrol = new InventoryControl(this);
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerInventoryViewListen(this), this);
|
||||
this.saveDefaultConfig();
|
||||
String worldname = getConfig().getString("Location.World");
|
||||
World world = Bukkit.getWorld(worldname);
|
||||
int x = getConfig().getInt("Location.X");
|
||||
int y = getConfig().getInt("Location.Y");
|
||||
int z = getConfig().getInt("Location.Z");
|
||||
loc = new Location(world, x, y, z);
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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/config.yml
Normal file
12
src/main/resources/config.yml
Normal file
@ -0,0 +1,12 @@
|
||||
#本文件为随身附魔台插件的主配置文件
|
||||
version: 1.0
|
||||
#服务器名称
|
||||
servername: ''
|
||||
#插件名称
|
||||
pluginname: '&6[&b随身附魔台&6]&r'
|
||||
|
||||
Location:
|
||||
World: world
|
||||
X: 0
|
||||
Y: 0
|
||||
Z: 0
|
Loading…
Reference in New Issue
Block a user