mirror of
https://e.coding.net/circlecloud/CityBuild.git
synced 2024-12-26 16:38:48 +00:00
init project...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
commit
fd5bab9e5b
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
# Eclipse stuff
|
||||
/.classpath
|
||||
/.project
|
||||
/.settings
|
||||
|
||||
# netbeans
|
||||
/nbproject
|
||||
|
||||
# we use maven!
|
||||
/build.xml
|
||||
|
||||
# maven
|
||||
/target
|
||||
/repo
|
||||
|
||||
# vim
|
||||
.*.sw[a-p]
|
||||
|
||||
# various other potential build files
|
||||
/build
|
||||
/bin
|
||||
/dist
|
||||
/manifest.mf
|
||||
|
||||
/world
|
||||
|
||||
# Mac filesystem dust
|
||||
*.DS_Store
|
||||
|
||||
# intellij
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# Project Stuff
|
||||
/src/main/resources/Soulbound
|
||||
|
||||
# Atlassian Stuff
|
||||
/atlassian-ide-plugin.xml
|
BIN
lib/Residence.jar
Normal file
BIN
lib/Residence.jar
Normal file
Binary file not shown.
53
pom.xml
Normal file
53
pom.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.CityCraft</groupId>
|
||||
<artifactId>CityBuild</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>CityBuild</name>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.8.3-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bekvon.bukkit.residence</groupId>
|
||||
<artifactId>Residence</artifactId>
|
||||
<version>2.6.6.6</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/Residence.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
52
src/cn/citycraft/CityBuild/CityBuild.java
Normal file
52
src/cn/citycraft/CityBuild/CityBuild.java
Normal file
@ -0,0 +1,52 @@
|
||||
package cn.citycraft.CityBuild;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.CityBuild.config.Config;
|
||||
import cn.citycraft.CityBuild.listen.Build;
|
||||
|
||||
public class CityBuild extends JavaPlugin implements CommandExecutor {
|
||||
public String servername;
|
||||
public String pluginname;
|
||||
public boolean tipplayer;
|
||||
|
||||
public void onLoad() {
|
||||
Config.load(this, "1.0");
|
||||
servername = getmessage("servername");
|
||||
pluginname = getmessage("pluginname");
|
||||
tipplayer = Config.getInstance().getBoolean("tipplayer");
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
Bukkit.getPluginManager().registerEvents(new Build(this), this);
|
||||
getLogger().info(pluginname + "城市世界建筑保护已加载!");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
getLogger().info(pluginname + "城市世界建筑保护已卸载!");
|
||||
}
|
||||
|
||||
public String getfullmsg(String path) {
|
||||
return servername + pluginname + " " + getmessage(path);
|
||||
}
|
||||
|
||||
public String getmessage(String path) {
|
||||
return Config.getMessage(path);
|
||||
}
|
||||
}
|
55
src/cn/citycraft/CityBuild/config/Config.java
Normal file
55
src/cn/citycraft/CityBuild/config/Config.java
Normal file
@ -0,0 +1,55 @@
|
||||
package cn.citycraft.CityBuild.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class Config extends ConfigLoader {
|
||||
private static String CONFIG_NAME = "config.yml";
|
||||
private static FileConfig instance;
|
||||
private static File file;
|
||||
|
||||
public Config(Plugin p) {
|
||||
super(p, CONFIG_NAME);
|
||||
file = new File(p.getDataFolder(), CONFIG_NAME);
|
||||
instance = super.getInstance();
|
||||
}
|
||||
|
||||
public Config(Plugin p, String ver) {
|
||||
super(p, CONFIG_NAME, ver);
|
||||
instance = super.getInstance();
|
||||
}
|
||||
|
||||
public static void load(Plugin p) {
|
||||
new Config(p);
|
||||
}
|
||||
|
||||
public static void load(Plugin p, String ver) {
|
||||
new Config(p, ver);
|
||||
}
|
||||
|
||||
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 String[] getStringArray(String path) {
|
||||
return instance.getStringList(path).toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static void save(){
|
||||
try {
|
||||
instance.save(file);
|
||||
} catch (IOException e) {
|
||||
saveError(file);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
102
src/cn/citycraft/CityBuild/config/ConfigLoader.java
Normal file
102
src/cn/citycraft/CityBuild/config/ConfigLoader.java
Normal file
@ -0,0 +1,102 @@
|
||||
package cn.citycraft.CityBuild.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ConfigLoader extends FileConfig {
|
||||
protected static FileConfig config;
|
||||
protected static boolean tip = true;
|
||||
protected static Plugin plugin;
|
||||
|
||||
public ConfigLoader(Plugin p, File file) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, file, null, true);
|
||||
}
|
||||
|
||||
public ConfigLoader(Plugin p, File file, boolean res) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, file, null, res);
|
||||
}
|
||||
|
||||
public ConfigLoader(Plugin p, File file, String ver) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, file, ver, true);
|
||||
}
|
||||
|
||||
public ConfigLoader(Plugin p, File file, String ver, boolean res) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, file, ver, res);
|
||||
}
|
||||
|
||||
public ConfigLoader(Plugin p, String filename) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, new File(p.getDataFolder(), filename), null,
|
||||
true);
|
||||
}
|
||||
|
||||
public ConfigLoader(Plugin p, String filename, boolean res) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, new File(p.getDataFolder(), filename), null, res);
|
||||
}
|
||||
|
||||
public ConfigLoader(Plugin p, String filename, String ver) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
|
||||
}
|
||||
|
||||
public ConfigLoader(Plugin p, String filename, String ver, boolean res) {
|
||||
ConfigLoader.plugin = p;
|
||||
config = loadConfig(p, new File(p.getDataFolder(), filename), ver, true);
|
||||
}
|
||||
|
||||
public static FileConfig getInstance() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public FileConfig loadConfig(Plugin p, File file, String ver, boolean res) {
|
||||
tip = res ;
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
p.getLogger().info("创建新的文件夹" + file.getParentFile().getAbsolutePath() + "...");
|
||||
}
|
||||
if (!file.exists()) {
|
||||
fileCreate(p, file, res);
|
||||
} else {
|
||||
if (ver != null) {
|
||||
FileConfig configcheck = init(file);
|
||||
String version = configcheck.getString("version");
|
||||
if (version == null || !version.equals(ver)) {
|
||||
p.saveResource(file.getName(), true);
|
||||
p.getLogger().warning(
|
||||
"配置文件: " + file.getName() + " 版本过低 正在升级...");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tip)
|
||||
p.getLogger().info(
|
||||
"载入配置文件: " + file.getName()
|
||||
+ (ver != null ? " 版本: " + ver : ""));
|
||||
return init(file);
|
||||
}
|
||||
|
||||
private void fileCreate(Plugin p, File file, boolean res) {
|
||||
if (res) {
|
||||
p.saveResource(file.getName(), false);
|
||||
} else {
|
||||
try {
|
||||
p.getLogger().info("创建新的配置文件" + file.getAbsolutePath() + "...");
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
p.getLogger().info("配置文件" + file.getName() + "创建失败...");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveError(File file) {
|
||||
plugin.getLogger().info("配置文件" + file.getName() + "保存错误...");
|
||||
}
|
||||
|
||||
}
|
88
src/cn/citycraft/CityBuild/config/FileConfig.java
Normal file
88
src/cn/citycraft/CityBuild/config/FileConfig.java
Normal file
@ -0,0 +1,88 @@
|
||||
package cn.citycraft.CityBuild.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConstructor;
|
||||
import org.bukkit.configuration.file.YamlRepresenter;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* An implementation of {@link Configuration} which saves all files in Yaml.
|
||||
* Note that this implementation is not synchronized.
|
||||
*/
|
||||
public class FileConfig extends YamlConfiguration {
|
||||
|
||||
protected final DumperOptions yamlOptions = new DumperOptions();
|
||||
protected final Representer yamlRepresenter = new YamlRepresenter();
|
||||
protected final Yaml yaml = new Yaml(new YamlConstructor(),
|
||||
yamlRepresenter, yamlOptions);
|
||||
|
||||
public static FileConfig init(File file) {
|
||||
return FileConfig.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static FileConfig loadConfiguration(File file) {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
FileConfig config = new FileConfig();
|
||||
try {
|
||||
config.load(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String saveToString() {
|
||||
yamlOptions.setIndent(options().indent());
|
||||
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
String header = buildHeader();
|
||||
String dump = yaml.dump(getValues(false));
|
||||
if (dump.equals(BLANK_CONFIG)) {
|
||||
dump = "";
|
||||
}
|
||||
return header + dump;
|
||||
}
|
||||
|
||||
public void load(File file) throws FileNotFoundException, IOException,
|
||||
InvalidConfigurationException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
final FileInputStream stream = new FileInputStream(file);
|
||||
load(new InputStreamReader(stream, Charsets.UTF_8));
|
||||
}
|
||||
|
||||
public void save(File file) throws IOException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
Files.createParentDirs(file);
|
||||
String data = saveToString();
|
||||
Writer writer = new OutputStreamWriter(new FileOutputStream(file),
|
||||
Charsets.UTF_8);
|
||||
try {
|
||||
writer.write(data);
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
106
src/cn/citycraft/CityBuild/listen/Build.java
Normal file
106
src/cn/citycraft/CityBuild/listen/Build.java
Normal file
@ -0,0 +1,106 @@
|
||||
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.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class Build implements Listener {
|
||||
|
||||
CityBuild plugin;
|
||||
|
||||
public Build(CityBuild main) {
|
||||
plugin = main;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void blockBreak(BlockBreakEvent event) {
|
||||
if (CancelEvent(event.getPlayer(), event.getBlock(), false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void blockplace(BlockPlaceEvent event) {
|
||||
if (CancelEvent(event.getPlayer(), event.getBlock(), true)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean CancelEvent(Player p, Block b, boolean place) {
|
||||
Location loc = b.getLocation();
|
||||
ClaimedResidence res = Residence.getResidenceManager().getByLoc(loc);
|
||||
if (res == null && !p.hasPermission("cb.build")) {
|
||||
String blockname = b.getType().name();
|
||||
World blockw = b.getWorld();
|
||||
int blockx = b.getX();
|
||||
int blocky = b.getY();
|
||||
int blockz = b.getZ();
|
||||
for (String protectworld : Config.getInstance().getStringList(
|
||||
"ProtectWorld")) {
|
||||
if (protectworld.equalsIgnoreCase(blockw.getName())) {
|
||||
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"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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 + ""));
|
||||
Bukkit.broadcast(
|
||||
plugin.getfullmsg("Message.Notice1")
|
||||
.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");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String[] message = { plugin.getfullmsg("Message.Wran"),
|
||||
plugin.getfullmsg("Message.Allow"),
|
||||
plugin.getfullmsg("Message.Relieve") };
|
||||
if (plugin.tipplayer)
|
||||
p.getPlayer().sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
59
src/config.yml
Normal file
59
src/config.yml
Normal file
@ -0,0 +1,59 @@
|
||||
#本文件为保护插件的主配置文件
|
||||
version: '1.0'
|
||||
#服务器名称
|
||||
servername: ''
|
||||
#插件名称
|
||||
pluginname: '&6[&3建筑保护&6]&r'
|
||||
#是否提示
|
||||
tipplayer: true
|
||||
#提示消息
|
||||
Message:
|
||||
Reload: '&a配置文件已重新载入!'
|
||||
#方块安全提示
|
||||
Tip: '&4未在领地内建筑 &c请确保您放置的方块安全 &e圈地后无提示!'
|
||||
|
||||
#未圈地超过建筑高度提示
|
||||
Max: '&c未在领地内建筑 请不要用&e泥土&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请管理到目标地点检查!'
|
||||
|
||||
#未圈地建筑提示
|
||||
#警告
|
||||
Wran: '&4城市世界除以下方块外禁止放置/破坏!'
|
||||
#允许的方块说明
|
||||
Allow: '&a允许的方块:&e箱子,&5熔炉,&a工作台,&6木板(树木),&d泥土,&9木门'
|
||||
#解除限制说明
|
||||
Relieve: '&c如需解除限制请圈地,&6工具:木锄&c,&b价格:0.3元/方块&c!'
|
||||
|
||||
|
||||
#城市保护配置
|
||||
#未圈地最大高度
|
||||
MaxHeight: 100
|
||||
|
||||
#受到保护的世界(不区分大小写)
|
||||
ProtectWorld:
|
||||
- FutureCity
|
||||
|
||||
#未圈地提示的ID列表
|
||||
NoticeList:
|
||||
- CHEST
|
||||
- FURNACE
|
||||
|
||||
#未圈地允许方块ID列表
|
||||
AllowList:
|
||||
- GRASS
|
||||
- DIRT
|
||||
- WOOD_DOOR
|
||||
- CHEST
|
||||
- FURNACE
|
||||
- WORKBENCH
|
||||
- WOOD
|
||||
- DIRT
|
||||
- TORCH
|
||||
- LONG_GRASS
|
||||
- DOUBLE_PLANT
|
||||
- RED_ROSE
|
||||
- LOG_2
|
||||
- LOG
|
27
src/plugin.yml
Normal file
27
src/plugin.yml
Normal file
@ -0,0 +1,27 @@
|
||||
name: CityBuild
|
||||
main: cn.citycraft.CityBuild.CityBuild
|
||||
version: 1.0
|
||||
depend: [Residence]
|
||||
commands:
|
||||
cb:
|
||||
description: 城市建筑插件命令
|
||||
usage: 使用/cb help查看帮助!
|
||||
permission: cb.use
|
||||
permission-message: §c你没有此命令的权限!
|
||||
permissions:
|
||||
cb.*:
|
||||
description: 允许使用所有命令!
|
||||
default: op
|
||||
children:
|
||||
cb.build: true
|
||||
cb.use: true
|
||||
cb.notice: true
|
||||
cb.use:
|
||||
description: 允许使用所有命令!
|
||||
default: op
|
||||
cb.build:
|
||||
description: 允许忽略插件的检测!
|
||||
default: op
|
||||
cb.notice:
|
||||
description: 允许接受插件的通知!
|
||||
default: op
|
Loading…
Reference in New Issue
Block a user