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,56 +1,102 @@
|
||||
package cn.citycraft.CityBuild;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.CityBuild.config.Config;
|
||||
import cn.citycraft.CityBuild.config.Data;
|
||||
import cn.citycraft.CityBuild.listen.Build;
|
||||
|
||||
public class CityBuild extends JavaPlugin implements CommandExecutor {
|
||||
public String servername;
|
||||
public String pluginname;
|
||||
public boolean tipplayer;
|
||||
public Map<Location, String> mhl;
|
||||
public String servername;
|
||||
public String pluginname;
|
||||
public boolean tipplayer;
|
||||
|
||||
public String getfullmsg(String path) {
|
||||
return servername + pluginname + " " + getmessage(path);
|
||||
}
|
||||
|
||||
public String getmessage(String path) {
|
||||
return Config.getMessage(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String string,
|
||||
String[] args) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
onLoad();
|
||||
sender.sendMessage(pluginname + getmessage("Message.Reload"));
|
||||
return true;
|
||||
}
|
||||
public String getfullmsg(String path) {
|
||||
return servername + pluginname + " " + getmessage(path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info(pluginname + "城市世界建筑保护已卸载!");
|
||||
}
|
||||
public String getmessage(String path) {
|
||||
return Config.getMessage(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(new Build(this), this);
|
||||
getLogger().info(pluginname + "城市世界建筑保护已加载!");
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) {
|
||||
if (args.length == 1) {
|
||||
switch (args[0]) {
|
||||
case "reload":
|
||||
Data.save();
|
||||
onLoad();
|
||||
sender.sendMessage(getfullmsg("Message.Reload"));
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Config.load(this, "1.1");
|
||||
servername = getmessage("servername");
|
||||
pluginname = getmessage("pluginname");
|
||||
tipplayer = Config.getInstance().getBoolean("tipplayer");
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Data.getInstance().set("MaxHeightList", mhl);
|
||||
Data.save();
|
||||
getLogger().info(pluginname + "城市世界建筑保护已卸载!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(new Build(this), this);
|
||||
getLogger().info(pluginname + "城市世界建筑保护已加载!");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onLoad() {
|
||||
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");
|
||||
pluginname = getmessage("pluginname");
|
||||
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;
|
||||
|
||||
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.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -18,6 +12,12 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
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 {
|
||||
|
||||
CityBuild plugin;
|
||||
@ -28,44 +28,14 @@ public class Build implements Listener {
|
||||
|
||||
// PlayerInteractEvent.class
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void playerInteract(PlayerInteractEvent event) {
|
||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getMaterial()));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void blockBreak(BlockBreakEvent event) {
|
||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(),
|
||||
false));
|
||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(), false));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void blockplace(BlockPlaceEvent event) {
|
||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(),
|
||||
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;
|
||||
event.setCancelled(CancelEvent(event.getPlayer(), event.getBlock(), true));
|
||||
}
|
||||
|
||||
public boolean CancelEvent(Player p, Block b, boolean place) {
|
||||
@ -77,46 +47,37 @@ public class Build implements Listener {
|
||||
int blockx = b.getX();
|
||||
int blocky = b.getY();
|
||||
int blockz = b.getZ();
|
||||
for (String protectworld : Config.getInstance().getStringList(
|
||||
"ProtectWorld")) {
|
||||
for (String protectworld : Config.getInstance().getStringList("ProtectWorld")) {
|
||||
if (protectworld.equalsIgnoreCase(blockw.getName())) {
|
||||
for (String allowblock : Config.getInstance()
|
||||
.getStringList("AllowList")) {
|
||||
for (String allowblock : Config.getInstance().getStringList("AllowList")) {
|
||||
if (blockname.equalsIgnoreCase(allowblock)) {
|
||||
for (String noticeblock : Config.getInstance()
|
||||
.getStringList("NoticeList")) {
|
||||
if (blockname.equalsIgnoreCase(noticeblock)
|
||||
&& place) {
|
||||
if (plugin.tipplayer)
|
||||
p.getPlayer()
|
||||
.sendMessage(
|
||||
plugin.getfullmsg("Message.Tip"));
|
||||
for (String noticeblock : Config.getInstance().getStringList(
|
||||
"NoticeList")) {
|
||||
if (blockname.equalsIgnoreCase(noticeblock) && place) {
|
||||
if (plugin.tipplayer) {
|
||||
p.getPlayer().sendMessage(plugin.getfullmsg("Message.Tip"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int maxheight = Config.getInstance().getInt(
|
||||
"MaxHeight");
|
||||
if (blocky > maxheight
|
||||
&& blockname.equalsIgnoreCase("Dirt")) {
|
||||
if (plugin.tipplayer)
|
||||
int maxheight = Config.getInstance().getInt("MaxHeight");
|
||||
if (blocky > maxheight && blockname.equalsIgnoreCase("Dirt")) {
|
||||
if (plugin.tipplayer) {
|
||||
p.getPlayer().sendMessage(
|
||||
plugin.getfullmsg("Message.Max")
|
||||
.replaceAll("%maxheight%",
|
||||
maxheight + ""));
|
||||
plugin.getfullmsg("Message.Max").replaceAll(
|
||||
"%maxheight%", maxheight + ""));
|
||||
}
|
||||
Bukkit.broadcast(
|
||||
plugin.getfullmsg("Message.Notice1")
|
||||
.replaceAll("%player%",
|
||||
p.getDisplayName())
|
||||
.replaceAll("%maxheight%",
|
||||
maxheight + ""),
|
||||
.replaceAll("%player%", p.getDisplayName())
|
||||
.replaceAll("%maxheight%", maxheight + ""),
|
||||
"cb.notice");
|
||||
Bukkit.broadcast(
|
||||
plugin.getfullmsg("Message.Notice2")
|
||||
.replaceAll("%world%",
|
||||
blockw.getName())
|
||||
.replaceAll("%x%", blockx + "")
|
||||
.replaceAll("%z%", blockz + ""),
|
||||
"cb.notice");
|
||||
.replaceAll("%world%", blockw.getName())
|
||||
.replaceAll("%x%", blockx + "")
|
||||
.replaceAll("%z%", blockz + ""), "cb.notice");
|
||||
plugin.mhl.put(loc, p.getName());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -125,12 +86,38 @@ public class Build implements Listener {
|
||||
String[] message = { plugin.getfullmsg("Message.Wran"),
|
||||
plugin.getfullmsg("Message.Allow"),
|
||||
plugin.getfullmsg("Message.Relieve") };
|
||||
if (plugin.tipplayer)
|
||||
if (plugin.tipplayer) {
|
||||
p.getPlayer().sendMessage(message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 的建筑物!'
|
||||
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城市世界除以下方块外禁止放置/破坏!'
|
||||
|
Loading…
Reference in New Issue
Block a user