This commit is contained in:
boy0001
2014-09-23 12:08:39 +10:00
15 changed files with 743 additions and 183 deletions

View File

@ -1,5 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="IntelliGuard" name="Obfuscation">
<configuration>
<option name="yGuardJar" value="C:\Users\Citymonstret\Desktop\lib\yguard.jar" />
<option name="mainclass" value="com.intellectualcrafters.plot.PlotMain" />
<option name="errorChecking" value="false" />
<option name="jarConfig">
<JarConfig>
<option name="jarEntries">
<list>
<option value="C:\Users\Citymonstret\Desktop\workspace\bukkit\plot_news\out\production\PlotSquared" />
</list>
</option>
</JarConfig>
</option>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">

View File

@ -23,6 +23,8 @@ public enum C {
SCHEMATIC_MISSING_ARG("&cYou need to specify an argument. Possible values: &6test {name}"),
SCHEMATIC_INVALID("&cThat is not a valid schematic. Reason: &c%s"),
SCHEMATIC_VALID("&cThat's a valid schematic"),
SCHEMATIC_PASTE_FAILED("&cFailed to paste schematic"),
SCHEMATIC_PASTE_SUCCESS("&cSchematic pasted successfully"),
/*
Title Stuff
*/

View File

@ -0,0 +1,88 @@
package com.intellectualcrafters.plot;
import org.bukkit.ChatColor;
/**
* Created by Citymonstret on 2014-09-22.
*/
public class ConsoleColors {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public static final String ANSI_BOLD = "\033[1m";
public static final String ANSI_UNDERLINE = "\033[0m";
public static final String ANSI_ITALIC = "\033[3m]";
public static String fromString(String input) {
input = input
.replaceAll("&0", fromChatColor(ChatColor.BLACK))
.replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE))
.replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN))
.replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA))
.replaceAll("&4", fromChatColor(ChatColor.DARK_RED))
.replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE))
.replaceAll("&6", fromChatColor(ChatColor.GOLD))
.replaceAll("&7", fromChatColor(ChatColor.GRAY))
.replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY))
.replaceAll("&9", fromChatColor(ChatColor.BLUE))
.replaceAll("&a", fromChatColor(ChatColor.GREEN))
.replaceAll("&b", fromChatColor(ChatColor.AQUA))
.replaceAll("&c", fromChatColor(ChatColor.RED))
.replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE))
.replaceAll("&e", fromChatColor(ChatColor.YELLOW))
.replaceAll("&f", fromChatColor(ChatColor.WHITE))
.replaceAll("&k", fromChatColor(ChatColor.MAGIC))
.replaceAll("&l", fromChatColor(ChatColor.BOLD))
.replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH))
.replaceAll("&n", fromChatColor(ChatColor.UNDERLINE))
.replaceAll("&o", fromChatColor(ChatColor.ITALIC))
.replaceAll("&r", fromChatColor(ChatColor.RESET))
;
return input + ANSI_RESET;
}
public static String fromChatColor(ChatColor color) {
switch(color) {
case RESET:
return ANSI_RESET;
case GRAY:
case DARK_GRAY:
return ANSI_WHITE;
case BLACK:
return ANSI_BLACK;
case DARK_RED:
case RED:
return ANSI_RED;
case GOLD:
case YELLOW:
return ANSI_YELLOW;
case DARK_GREEN:
case GREEN:
return ANSI_GREEN;
case AQUA:
case DARK_AQUA:
return ANSI_CYAN;
case LIGHT_PURPLE:
case DARK_PURPLE:
return ANSI_PURPLE;
case BLUE:
case DARK_BLUE:
return ANSI_BLUE;
case UNDERLINE:
return ANSI_UNDERLINE;
case ITALIC:
return ANSI_ITALIC;
case BOLD:
return ANSI_BOLD;
default:
return "";
}
}
}

View File

@ -129,8 +129,6 @@ public class PlayerFunctions {
return plots.get(id);
}
}
else {
}
return new Plot(id, null, Biome.FOREST, new ArrayList<UUID>(), new ArrayList<UUID>(), world.getName());
}

View File

@ -326,6 +326,27 @@ public class PlotMain extends JavaPlugin {
}
}
private void setupLogger() {
File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log");
if (!log.exists()) {
try {
if (!new File(getMain().getDataFolder() + File.separator + "logs").mkdirs()) {
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to create logs folder. Do it manually.");
}
if (log.createNewFile()) {
FileWriter writer = new FileWriter(log);
writer.write("Created at: " + new Date().toString() + "\n\n\n");
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
Logger.setup(log);
Logger.add(LogLevel.GENERAL, "Logger enabled");
}
/**
* On Load.
* TODO: Load updates async
@ -333,26 +354,8 @@ public class PlotMain extends JavaPlugin {
@Override
@SuppressWarnings("deprecation")
public void onEnable() {
{
File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log");
if (!log.exists()) {
try {
if (!new File(getMain().getDataFolder() + File.separator + "logs").mkdirs()) {
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to create logs folder. Do it manually.");
}
if (log.createNewFile()) {
FileWriter writer = new FileWriter(log);
writer.write("Created at: " + new Date().toString() + "\n\n\n");
writer.close();
}
} catch (IOException e) {
setupLogger();
e.printStackTrace();
}
}
Logger.setup(log);
Logger.add(LogLevel.GENERAL, "Logger enabled");
}
configs();
// TODO make this configurable
@ -466,10 +469,15 @@ public class PlotMain extends JavaPlugin {
100L, 1L);
if(Web.ENABLED) {
sendConsoleSenderMessage("This is not yet implemented...");
sendConsoleSenderMessage(C.PREFIX.s() + "This is not yet implemented...");
}
}
private void options(boolean verbose) {
}
/**
* Get MySQL Connection
*
@ -510,7 +518,11 @@ public class PlotMain extends JavaPlugin {
* @param string message
*/
public static void sendConsoleSenderMessage(String string) {
getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
if(getMain().getServer().getConsoleSender() == null) {
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string)));
} else {
getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
}
}
public static boolean teleportPlayer(Player player, Location from, Plot plot) {
@ -640,10 +652,6 @@ public class PlotMain extends JavaPlugin {
Settings.DB.DATABASE = storage.getString("mysql_database");
}
{
Settings.Update.AUTO_UPDATE = config.getBoolean("auto_update");
//Web
Web.ENABLED = config.getBoolean("web.enabled");
Web.PORT = config.getInt("web.port");
@ -667,7 +675,7 @@ public class PlotMain extends JavaPlugin {
World world = Bukkit.getWorld(w);
try {
if(world.getLoadedChunks().length < 1) {
return;
continue;
}
for (Chunk chunk : world.getLoadedChunks()) {
for (Entity entity : chunk.getEntities()){
@ -711,7 +719,7 @@ public class PlotMain extends JavaPlugin {
}
else {
ChunkGenerator gen = world.getGenerator();
if (gen==null || gen.toString().equals("PlotSquared")) {
if (gen==null || !gen.toString().equals("PlotSquared")) {
Logger.add(LogLevel.WARNING, "World '"+node+"' in settings.yml is not using PlotSquared generator");
}
}

View File

@ -1,9 +1,9 @@
package com.intellectualcrafters.plot;
import java.util.ArrayList;
import org.bukkit.Material;
import java.util.ArrayList;
public class PlotWorld {
/**
* Road Height
@ -159,5 +159,9 @@ public class PlotWorld {
* Blocks available in /p set
*/
public static ArrayList<Material> BLOCKS = new ArrayList<Material>();
public boolean SCHEMATIC_ON_CLAIM = false;
public String SCHEMATIC_FILE = "null";
}

View File

@ -1,8 +1,11 @@
package com.intellectualcrafters.plot;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import org.bukkit.Location;
import org.bukkit.World;
import java.io.File;
import java.io.FileInputStream;
@ -16,23 +19,21 @@ import java.util.zip.GZIPInputStream;
public class SchematicHandler {
@SuppressWarnings("deprecation")
public boolean paste(Location location, Schematic schematic) {
public boolean paste(Location location, Schematic schematic, Plot plot){
if(schematic == null) {
PlotMain.sendConsoleSenderMessage("Schematic == null :|");
return false;
}
Dimension dimension = schematic.getSchematicDimension();
DataCollection[] collection = schematic.getBlockCollection();
World world = location.getWorld();
for(int x = 0; x < dimension.getX(); x++) {
for(int y = 0; y < dimension.getY(); y++) {
for(int z = 0; z < dimension.getZ(); z++) {
DataCollection current = collection[getCurrent(x, y, z, dimension)];
(new Location(world, location.getBlockX() + x, location.getBlockY() + y, location.getBlockZ() + z).getBlock()).setTypeIdAndData(current.getBlock(), current.getData(), true);
}
}
try {
EditSession session = new EditSession(new BukkitWorld(location.getWorld()), 999999999);
CuboidClipboard clipboard = CuboidClipboard.loadSchematic(schematic.getFile());
Location l1 = PlotHelper.getPlotBottomLoc(plot.getWorld(), plot.getId());
Location l2 = PlotHelper.getPlotTopLoc(plot.getWorld(), plot.getId());
PlotWorld plotWorld = PlotMain.getWorldSettings(plot.getWorld());
Vector v1 = new Vector(l1.getBlockX() + 1, plotWorld.PLOT_HEIGHT + 2, l1.getBlockZ() + 1);
clipboard.paste(session, v1, true);
} catch(Exception e) {
return false;
}
return true;
}
@ -90,7 +91,7 @@ public class SchematicHandler {
collection[x] = new DataCollection(blocks[x], d[x]);
}
schematic = new Schematic(collection, dimension);
schematic = new Schematic(collection, dimension, file);
} catch(Exception e) {
e.printStackTrace();
return null;
@ -103,13 +104,19 @@ public class SchematicHandler {
return (x * dimension.getX()) + (y * dimension.getY()) + (z * dimension.getZ());
}
public class Schematic {
public static class Schematic {
private DataCollection[] blockCollection;
private Dimension schematicDimension;
private File file;
public Schematic(DataCollection[] blockCollection, Dimension schematicDimension) {
public Schematic(DataCollection[] blockCollection, Dimension schematicDimension, File file) {
this.blockCollection = blockCollection;
this.schematicDimension = schematicDimension;
this.file = file;
}
public File getFile() {
return this.file;
}
public Dimension getSchematicDimension() {

View File

@ -55,6 +55,12 @@ public class Claim extends SubCommand{
if(teleport) {
PlotMain.teleportPlayer(player, player.getLocation(), plot);
}
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if(world.SCHEMATIC_ON_CLAIM) {
SchematicHandler handler = new SchematicHandler();
SchematicHandler.Schematic schematic = handler.getSchematic(world.SCHEMATIC_FILE);
handler.paste(player.getLocation(), schematic, plot);
}
}
return event.isCancelled();
}

View File

@ -1,10 +1,9 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.SchematicHandler;
import com.intellectualcrafters.plot.Settings;
import org.bukkit.entity.Player;
public class Schematic extends SubCommand {
@ -21,14 +20,34 @@ public class Schematic extends SubCommand {
return true;
}
String arg = args[0];
String file;
SchematicHandler.Schematic schematic;
switch(arg) {
case "paste":
if(args.length < 2) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
if(!PlayerFunctions.isInPlot(plr)) {
sendMessage(plr, C.NOT_IN_PLOT);
break;
}
file = args[1];
schematic = new SchematicHandler().getSchematic(file);
boolean s = new SchematicHandler().paste(plr.getLocation(), schematic, PlayerFunctions.getCurrentPlot(plr));
if(s) {
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
} else {
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
}
break;
case "test":
if(args.length < 2) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
String file = args[1];
SchematicHandler.Schematic schematic = new SchematicHandler().getSchematic(file);
file = args[1];
schematic = new SchematicHandler().getSchematic(file);
if(schematic == null) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
break;

View File

@ -2,12 +2,12 @@ name: PlotSquared
main: com.intellectualcrafters.plot.PlotMain
version: 1.0
load: STARTUP
description: >
description: >
Easy, yet powerful Plot World generation and management.
authors: [Citymonstret, brandonrelph]
softdepend: [WorldEdit, BarAPI, PlotMe, CameraAPI]
database: false
commands:
commands:
plots:
description: PlotMain PlotSquared command.
aliases: [p,plotme,plot]
@ -17,5 +17,5 @@ permissions:
default: op
plots.admin:
default: op
plots.worldedit.bypass:
defautl: false
plots.worldedit.bypass:
default: false