mirror of
https://e.coding.net/circlecloud/CityBuild.git
synced 2024-11-21 10:48:49 +00:00
Update...
This commit is contained in:
parent
8bd17f37c6
commit
51400658c0
@ -1,15 +1,24 @@
|
|||||||
package cn.citycraft.CityBuild;
|
package cn.citycraft.CityBuild;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import cn.citycraft.CityBuild.config.Config;
|
import cn.citycraft.CityBuild.config.Config;
|
||||||
|
import cn.citycraft.CityBuild.config.Data;
|
||||||
import cn.citycraft.CityBuild.listen.Build;
|
import cn.citycraft.CityBuild.listen.Build;
|
||||||
|
|
||||||
public class CityBuild extends JavaPlugin implements CommandExecutor {
|
public class CityBuild extends JavaPlugin implements CommandExecutor {
|
||||||
|
public Map<Location, String> mhl;
|
||||||
public String servername;
|
public String servername;
|
||||||
public String pluginname;
|
public String pluginname;
|
||||||
public boolean tipplayer;
|
public boolean tipplayer;
|
||||||
@ -23,13 +32,42 @@ public class CityBuild extends JavaPlugin implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String string,
|
public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) {
|
||||||
String[] args) {
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
switch (args[0]) {
|
||||||
|
case "reload":
|
||||||
|
Data.save();
|
||||||
onLoad();
|
onLoad();
|
||||||
sender.sendMessage(pluginname + getmessage("Message.Reload"));
|
sender.sendMessage(getfullmsg("Message.Reload"));
|
||||||
return true;
|
return true;
|
||||||
|
case "look":
|
||||||
|
sender.sendMessage(getfullmsg("Message.Look"));
|
||||||
|
if (mhl.isEmpty()) {
|
||||||
|
sender.sendMessage(getfullmsg("Message.NotHave"));
|
||||||
|
} else {
|
||||||
|
for (Entry<Location, String> info : mhl.entrySet()) {
|
||||||
|
String name = info.getValue();
|
||||||
|
Location loc = info.getKey();
|
||||||
|
World w = loc.getWorld();
|
||||||
|
int x = loc.getBlockX();
|
||||||
|
int z = loc.getBlockZ();
|
||||||
|
sender.sendMessage(getfullmsg("Message.Info").replaceAll("%player%", name)
|
||||||
|
.replaceAll("%world%", w.getName()).replaceAll("%x%", x + "")
|
||||||
|
.replaceAll("%z%", z + ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case "clear":
|
||||||
|
mhl.clear();
|
||||||
|
Data.getInstance().set("MaxHeightList", null);
|
||||||
|
Data.save();
|
||||||
|
sender.sendMessage(getfullmsg("Message.NotHave"));
|
||||||
|
return true;
|
||||||
|
case "put":
|
||||||
|
Player p = (Player) sender;
|
||||||
|
mhl.put(p.getLocation(), p.getName());
|
||||||
|
Data.getInstance().set("MaxHeightList", mhl);
|
||||||
|
Data.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -37,6 +75,8 @@ public class CityBuild extends JavaPlugin implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
Data.getInstance().set("MaxHeightList", mhl);
|
||||||
|
Data.save();
|
||||||
getLogger().info(pluginname + "城市世界建筑保护已卸载!");
|
getLogger().info(pluginname + "城市世界建筑保护已卸载!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,9 +86,15 @@ public class CityBuild extends JavaPlugin implements CommandExecutor {
|
|||||||
getLogger().info(pluginname + "城市世界建筑保护已加载!");
|
getLogger().info(pluginname + "城市世界建筑保护已加载!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
Config.load(this, "1.1");
|
Config.load(this, "1.1");
|
||||||
|
Data.load(this);
|
||||||
|
mhl = (Map<Location, String>) Config.getInstance().get("MaxHeightList");
|
||||||
|
if (mhl == null) {
|
||||||
|
mhl = new HashMap<>();
|
||||||
|
}
|
||||||
servername = getmessage("servername");
|
servername = getmessage("servername");
|
||||||
pluginname = getmessage("pluginname");
|
pluginname = getmessage("pluginname");
|
||||||
tipplayer = Config.getInstance().getBoolean("tipplayer");
|
tipplayer = Config.getInstance().getBoolean("tipplayer");
|
||||||
|
43
src/cn/citycraft/CityBuild/config/Data.java
Normal file
43
src/cn/citycraft/CityBuild/config/Data.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package cn.citycraft.CityBuild.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class Data extends ConfigLoader {
|
||||||
|
private static String CONFIG_NAME = "data.yml";
|
||||||
|
private static FileConfig instance;
|
||||||
|
private static File file;
|
||||||
|
|
||||||
|
public static FileConfig getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMessage(String path) {
|
||||||
|
String message = instance.getString(path);
|
||||||
|
if (message != null) {
|
||||||
|
message = message.replaceAll("&", "§");
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void load(Plugin p) {
|
||||||
|
new Data(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void save() {
|
||||||
|
try {
|
||||||
|
instance.save(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
saveError(file);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Data(Plugin p) {
|
||||||
|
super(p, CONFIG_NAME, false);
|
||||||
|
file = new File(p.getDataFolder(), CONFIG_NAME);
|
||||||
|
instance = super.getInstance();
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,5 @@
|
|||||||
package cn.citycraft.CityBuild.listen;
|
package cn.citycraft.CityBuild.listen;
|
||||||
|
|
||||||
import cn.citycraft.CityBuild.CityBuild;
|
|
||||||
import cn.citycraft.CityBuild.config.Config;
|
|
||||||
|
|
||||||
import com.bekvon.bukkit.residence.Residence;
|
|
||||||
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -18,6 +12,12 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
import cn.citycraft.CityBuild.CityBuild;
|
||||||
|
import cn.citycraft.CityBuild.config.Config;
|
||||||
|
|
||||||
|
import com.bekvon.bukkit.residence.Residence;
|
||||||
|
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||||
|
|
||||||
public class Build implements Listener {
|
public class Build implements Listener {
|
||||||
|
|
||||||
CityBuild plugin;
|
CityBuild plugin;
|
||||||
@ -28,44 +28,14 @@ public class Build implements Listener {
|
|||||||
|
|
||||||
// PlayerInteractEvent.class
|
// PlayerInteractEvent.class
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void playerInteract(PlayerInteractEvent event) {
|
|
||||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getMaterial()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void blockBreak(BlockBreakEvent event) {
|
public void blockBreak(BlockBreakEvent event) {
|
||||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(),
|
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(), false));
|
||||||
false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void blockplace(BlockPlaceEvent event) {
|
public void blockplace(BlockPlaceEvent event) {
|
||||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(),
|
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(), true));
|
||||||
true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean CancelEvent(Player p, Material m) {
|
|
||||||
ClaimedResidence res = Residence.getResidenceManager().getByLoc(
|
|
||||||
p.getLocation());
|
|
||||||
if (res == null && !p.hasPermission("cb.build")) {
|
|
||||||
String blockname = m.name();
|
|
||||||
for (String protectworld : Config.getInstance().getStringList(
|
|
||||||
"ProtectWorld")) {
|
|
||||||
if (protectworld.equalsIgnoreCase(p.getWorld().getName())) {
|
|
||||||
for (String notallowblock : Config.getInstance()
|
|
||||||
.getStringList("NotAllowList")) {
|
|
||||||
if (blockname.equalsIgnoreCase(notallowblock)) {
|
|
||||||
if (plugin.tipplayer)
|
|
||||||
p.getPlayer().sendMessage(
|
|
||||||
plugin.getfullmsg("Message.NotAllow"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean CancelEvent(Player p, Block b, boolean place) {
|
public boolean CancelEvent(Player p, Block b, boolean place) {
|
||||||
@ -77,46 +47,37 @@ public class Build implements Listener {
|
|||||||
int blockx = b.getX();
|
int blockx = b.getX();
|
||||||
int blocky = b.getY();
|
int blocky = b.getY();
|
||||||
int blockz = b.getZ();
|
int blockz = b.getZ();
|
||||||
for (String protectworld : Config.getInstance().getStringList(
|
for (String protectworld : Config.getInstance().getStringList("ProtectWorld")) {
|
||||||
"ProtectWorld")) {
|
|
||||||
if (protectworld.equalsIgnoreCase(blockw.getName())) {
|
if (protectworld.equalsIgnoreCase(blockw.getName())) {
|
||||||
for (String allowblock : Config.getInstance()
|
for (String allowblock : Config.getInstance().getStringList("AllowList")) {
|
||||||
.getStringList("AllowList")) {
|
|
||||||
if (blockname.equalsIgnoreCase(allowblock)) {
|
if (blockname.equalsIgnoreCase(allowblock)) {
|
||||||
for (String noticeblock : Config.getInstance()
|
for (String noticeblock : Config.getInstance().getStringList(
|
||||||
.getStringList("NoticeList")) {
|
"NoticeList")) {
|
||||||
if (blockname.equalsIgnoreCase(noticeblock)
|
if (blockname.equalsIgnoreCase(noticeblock) && place) {
|
||||||
&& place) {
|
if (plugin.tipplayer) {
|
||||||
if (plugin.tipplayer)
|
p.getPlayer().sendMessage(plugin.getfullmsg("Message.Tip"));
|
||||||
p.getPlayer()
|
}
|
||||||
.sendMessage(
|
|
||||||
plugin.getfullmsg("Message.Tip"));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int maxheight = Config.getInstance().getInt(
|
int maxheight = Config.getInstance().getInt("MaxHeight");
|
||||||
"MaxHeight");
|
if (blocky > maxheight && blockname.equalsIgnoreCase("Dirt")) {
|
||||||
if (blocky > maxheight
|
if (plugin.tipplayer) {
|
||||||
&& blockname.equalsIgnoreCase("Dirt")) {
|
|
||||||
if (plugin.tipplayer)
|
|
||||||
p.getPlayer().sendMessage(
|
p.getPlayer().sendMessage(
|
||||||
plugin.getfullmsg("Message.Max")
|
plugin.getfullmsg("Message.Max").replaceAll(
|
||||||
.replaceAll("%maxheight%",
|
"%maxheight%", maxheight + ""));
|
||||||
maxheight + ""));
|
}
|
||||||
Bukkit.broadcast(
|
Bukkit.broadcast(
|
||||||
plugin.getfullmsg("Message.Notice1")
|
plugin.getfullmsg("Message.Notice1")
|
||||||
.replaceAll("%player%",
|
.replaceAll("%player%", p.getDisplayName())
|
||||||
p.getDisplayName())
|
.replaceAll("%maxheight%", maxheight + ""),
|
||||||
.replaceAll("%maxheight%",
|
|
||||||
maxheight + ""),
|
|
||||||
"cb.notice");
|
"cb.notice");
|
||||||
Bukkit.broadcast(
|
Bukkit.broadcast(
|
||||||
plugin.getfullmsg("Message.Notice2")
|
plugin.getfullmsg("Message.Notice2")
|
||||||
.replaceAll("%world%",
|
.replaceAll("%world%", blockw.getName())
|
||||||
blockw.getName())
|
|
||||||
.replaceAll("%x%", blockx + "")
|
.replaceAll("%x%", blockx + "")
|
||||||
.replaceAll("%z%", blockz + ""),
|
.replaceAll("%z%", blockz + ""), "cb.notice");
|
||||||
"cb.notice");
|
plugin.mhl.put(loc, p.getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -125,12 +86,38 @@ public class Build implements Listener {
|
|||||||
String[] message = { plugin.getfullmsg("Message.Wran"),
|
String[] message = { plugin.getfullmsg("Message.Wran"),
|
||||||
plugin.getfullmsg("Message.Allow"),
|
plugin.getfullmsg("Message.Allow"),
|
||||||
plugin.getfullmsg("Message.Relieve") };
|
plugin.getfullmsg("Message.Relieve") };
|
||||||
if (plugin.tipplayer)
|
if (plugin.tipplayer) {
|
||||||
p.getPlayer().sendMessage(message);
|
p.getPlayer().sendMessage(message);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean CancelEvent(Player p, Material m) {
|
||||||
|
ClaimedResidence res = Residence.getResidenceManager().getByLoc(p.getLocation());
|
||||||
|
if (res == null && !p.hasPermission("cb.build")) {
|
||||||
|
String blockname = m.name();
|
||||||
|
for (String protectworld : Config.getInstance().getStringList("ProtectWorld")) {
|
||||||
|
if (protectworld.equalsIgnoreCase(p.getWorld().getName())) {
|
||||||
|
for (String notallowblock : Config.getInstance().getStringList("NotAllowList")) {
|
||||||
|
if (blockname.equalsIgnoreCase(notallowblock)) {
|
||||||
|
if (plugin.tipplayer) {
|
||||||
|
p.getPlayer().sendMessage(plugin.getfullmsg("Message.NotAllow"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void playerInteract(PlayerInteractEvent event) {
|
||||||
|
event.setCancelled(CancelEvent(event.getPlayer(), event.getMaterial()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,10 @@ Message:
|
|||||||
#管理组收到的提示
|
#管理组收到的提示
|
||||||
Notice1: '&6玩家&r:&a%player%&e未在领地内&c用&3泥土&c建筑高度超过 &5%maxheight%&c 的建筑物!'
|
Notice1: '&6玩家&r:&a%player%&e未在领地内&c用&3泥土&c建筑高度超过 &5%maxheight%&c 的建筑物!'
|
||||||
Notice2: '&5坐标定位&r:&a世界%world% &dX:%x% Z:%z% &4请管理到目标地点检查!'
|
Notice2: '&5坐标定位&r:&a世界%world% &dX:%x% Z:%z% &4请管理到目标地点检查!'
|
||||||
|
Look: '&c当前已检测到有可能的擎天柱数据如下: '
|
||||||
|
Info: '&6玩家&r:&a%player%&e在地点&r:&a世界%world% &dX:%x% Z:%z% &c建筑过高&4请检查!'
|
||||||
|
NotHave: '&5未找到有可能的擎天柱数据!'
|
||||||
|
Clear: '&c已清理擎天柱数据!'
|
||||||
#未圈地建筑提示
|
#未圈地建筑提示
|
||||||
#警告
|
#警告
|
||||||
Wran: '&4城市世界除以下方块外禁止放置/破坏!'
|
Wran: '&4城市世界除以下方块外禁止放置/破坏!'
|
||||||
|
Loading…
Reference in New Issue
Block a user