Created
February 11, 2018 19:29
-
-
Save Densyakun/e97ae57eedcf08f605b509c13532a9b2 to your computer and use it in GitHub Desktop.
[BukkitPlugin]開発を中止したブロックのデータをファイル化するBukkitプラグイン「Builds」のソースコード。CSVManagerが必要: https://github.com/Densyakun/CSVManager Builds公式Wiki: http://bukkitbuilds.wiki.fc2.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.densyakun.bukkit.builds; | |
import java.io.File; | |
import java.io.IOException; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import java.util.Date; | |
import java.util.List; | |
import org.bukkit.ChatColor; | |
import org.bukkit.Material; | |
import org.bukkit.World; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.densyakun.csvm.CSVFile; | |
/** | |
* @author Densyakun | |
*/ | |
public class Main extends JavaPlugin { | |
public static final String bdver = "1.0"; | |
private File dir = new File("./plugins/Builds"); | |
@Override | |
public void onEnable() { | |
System.out.println(new StringBuffer("[Builds] bdver: ").append(bdver).toString()); | |
dir.mkdirs(); | |
} | |
@Override | |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
if (sender instanceof Player) { | |
if (command.getName().equalsIgnoreCase("build")) { | |
if (args.length == 0) { | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] パラメーターがありません").toString()); | |
} else { | |
if (args.length == 1) { | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] パラメーターが足りません").toString()); | |
} else if (args[0].equalsIgnoreCase("build")) { | |
CSVFile bdf = new CSVFile(new File(dir,new StringBuffer(args[1]).append(".bd").toString())); | |
if (bdf.getFile().exists()) { | |
try { | |
List<List<String>> lines = bdf.AllRead(); | |
bdf = null; | |
if (0 < lines.size()) { | |
int sizex = -1; | |
int sizey = -1; | |
int sizez = -1; | |
sizex = Integer.valueOf(lines.get(0).get(1)); | |
sizey = Integer.valueOf(lines.get(0).get(2)); | |
sizez = Integer.valueOf(lines.get(0).get(3)); | |
if ((sizex == -1) || (sizey == -1) || (sizez == -1)) { | |
sender.sendMessage(new StringBuilder(ChatColor.RED.toString()).append("[Builds] ファイルの読み込みに失敗しました Error: 2").toString()); | |
} else { | |
if (lines.get(0).get(0).equals(bdver)) { | |
Material[][][] mat = new Material[sizex][sizey][sizez]; | |
for (int a = 1; a < lines.size(); a++) { | |
mat[Integer.valueOf(lines.get(a).get(0))][Integer.valueOf(lines.get(a).get(1))][Integer.valueOf(lines.get(a).get(2))] = Material.getMaterial(lines.get(a).get(3)); | |
} | |
for (int x = 0; x < mat.length; x++) { | |
for (int y = 0; y < mat[x].length; y++) { | |
for (int z = 0; z < mat[x][y].length; z++) { | |
if (mat[x][y][z] == null) { | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] 問題のある素材情報がありました Error: 4 X: ").append(x).append(" Y: ").append(y).append(" Z: ").append(z).toString()); | |
} else { | |
((Player) sender) .getWorld().getBlockAt(((Player) sender) .getLocation().getBlockX() + x, ((Player) sender) .getLocation().getBlockY() + y, ((Player) sender) .getLocation().getBlockZ() + z).setType(mat[x][y][z]); | |
} | |
} | |
} | |
} | |
sender.sendMessage(new StringBuffer(ChatColor.AQUA.toString()).append("[Builds] 建造物の建築に成功しました").toString()); | |
} else { | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] ファイルの読み込みに失敗しました Error: 3").toString()); | |
} | |
} | |
} else { | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] ファイルの読み込みに失敗しました Error: 1").toString()); | |
} | |
lines = null; | |
} catch (IOException e) { | |
e.printStackTrace(); | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] ファイルの読み込みに失敗しました Error: 0").toString()); | |
} | |
} else { | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] 指定した.bdファイルは存在しません").toString()); | |
} | |
} else if (args[0].equalsIgnoreCase("copy")) { | |
if (args.length < 7) { | |
sender.sendMessage(new StringBuffer(ChatColor.RED.toString()).append("[Builds] パラメーターが足りません").toString()); | |
} else { | |
int x0 = Integer.valueOf(args[1]); | |
int y0 = Integer.valueOf(args[2]); | |
int z0 = Integer.valueOf(args[3]); | |
int x1 = Integer.valueOf(args[4]); | |
int y1 = Integer.valueOf(args[5]); | |
int z1 = Integer.valueOf(args[6]); | |
if (x0 > x1) { | |
int a = x0; | |
x0 = x1; | |
x1 = a; | |
} | |
if (y0 > y1) { | |
int a = y0; | |
y0 = y1; | |
y1 = a; | |
} | |
if (z0 > z1) { | |
int a = z0; | |
z0 = z1; | |
z1 = a; | |
} | |
World world = ((Player) sender) .getWorld(); | |
CSVFile bdf = new CSVFile(new File(dir, new StringBuffer(new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date())).append(".bd").toString())); | |
try { | |
bdf.getFile().createNewFile(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
List<List<String>> lines = new ArrayList<List<String>>(); | |
List<String> data = new ArrayList<String>(); | |
data.add(bdver); | |
data.add(String.valueOf(x1 - x0 + 1)); | |
data.add(String.valueOf(y1 - y0 + 1)); | |
data.add(String.valueOf(z1 - z0 + 1)); | |
lines.add(data); | |
data = null; | |
for (int x = x0; x <= x1; x++) { | |
for (int y = y0; y <= y1; y++) { | |
for (int z = z0; z <= z1; z++) { | |
List<String> line = new ArrayList<String>(); | |
line.add(String.valueOf(x - x0)); | |
line.add(String.valueOf(y - y0)); | |
line.add(String.valueOf(z - z0)); | |
line.add(world.getBlockAt(x, y, z).getType().toString()); | |
lines.add(line); | |
line = null; | |
} | |
} | |
} | |
world = null; | |
try { | |
bdf.AllWrite(lines); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
bdf = null; | |
lines = null; | |
sender.sendMessage(new StringBuffer(ChatColor.AQUA.toString()).append("指定した範囲のbdファイルを作成しました").toString()); | |
} | |
} | |
} | |
} | |
} else { | |
sender.sendMessage("[Builds] このコマンドはプレイヤーのみ実行できます"); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment