Merge remote-tracking branch 'origin/master'

Conflicts:
	PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java
This commit is contained in:
boy0001
2014-10-26 11:07:12 +11:00
11 changed files with 207 additions and 658 deletions

View File

@ -1,7 +1,6 @@
package com.intellectualcrafters.plot;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
public class Flag {
private AbstractFlag key;
@ -21,8 +20,14 @@ public class Flag {
* if you provide inadequate inputs
*/
public Flag(AbstractFlag key, String value) {
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', value)))) {
throw new IllegalArgumentException("Flag must be alphanumerical");
char[] allowedCharacters = new char[] {
'[', ']', '(', ')', ',', '_', '-', '.', ',', '?', '!', '&', '§'
};
String tempValue = value;
for(char c : allowedCharacters)
tempValue = tempValue.replace(c, 'c');
if (!StringUtils.isAlphanumericSpace(tempValue)) {
throw new IllegalArgumentException("Flag must be alphanumerical (colours and some special characters are allowed)");
}
if (value.length() > 48) {
throw new IllegalArgumentException("Value must be <= 48 characters");

View File

@ -9,16 +9,10 @@
package com.intellectualcrafters.plot;
import ca.mera.CameraAPI;
import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.Settings.Web;
import com.intellectualcrafters.plot.commands.Camera;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.PlotMeConverter;
import com.intellectualcrafters.plot.database.SQLManager;
import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.database.*;
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.generator.DefaultPlotManager;
@ -31,10 +25,8 @@ import com.intellectualcrafters.plot.uuid.PlotUUIDSaver;
import com.intellectualcrafters.plot.uuid.UUIDSaver;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import me.confuser.barapi.BarAPI;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
@ -718,10 +710,6 @@ public class PlotMain extends JavaPlugin {
useEconomy = (economy != null);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Lag(), 100L, 1L);
if (Web.ENABLED) {
sendConsoleSenderMessage(C.PREFIX.s() + "Web Is not implemented yet. Please bear with us.");
}
try {
new SetBlockFast();
PlotHelper.canSetFast = true;
@ -938,6 +926,7 @@ public class PlotMain extends JavaPlugin {
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban");
Settings.SCHEMATIC_SAVE_PATH = config.getString("schematic.save_path");
}
if (Settings.DEBUG) {
Map<String, String> settings = new HashMap<>();
@ -945,12 +934,11 @@ public class PlotMain extends JavaPlugin {
settings.put("Use Metrics", "" + Settings.METRICS);
settings.put("Delete Plots On Ban", "" + Settings.DELETE_PLOTS_ON_BAN);
settings.put("Mob Pathfinding", "" + Settings.MOB_PATHFINDING);
settings.put("Web Enabled", "" + Web.ENABLED);
settings.put("Web Port", "" + Web.PORT);
settings.put("DB Mysql Enabled", "" + Settings.DB.USE_MYSQL);
settings.put("DB SQLite Enabled", "" + Settings.DB.USE_SQLITE);
settings.put("Auto Clear Enabled", "" + Settings.AUTO_CLEAR);
settings.put("Auto Clear Days", "" + Settings.AUTO_CLEAR_DAYS);
settings.put("Schematics Save Path", "" + Settings.SCHEMATIC_SAVE_PATH);
for (Entry<String, String> setting : settings.entrySet()) {
sendConsoleSenderMessage(C.PREFIX.s()
+ String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue()));
@ -1077,9 +1065,6 @@ public class PlotMain extends JavaPlugin {
options.put("worldguard.enabled", Settings.WORLDGUARD);
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
options.put("web.enabled", Web.ENABLED);
options.put("web.directory", "/var/www");
options.put("web.port", Web.PORT);
options.put("metrics", true);
options.put("debug", true);
options.put("clear.auto.enabled", false);
@ -1096,9 +1081,6 @@ public class PlotMain extends JavaPlugin {
if (Settings.DEBUG) {
sendConsoleSenderMessage(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
}
Web.ENABLED = config.getBoolean("web.enabled");
Web.PORT = config.getInt("web.port");
Web.PATH = config.getString("web.directory");
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
Settings.WORLDGUARD = config.getBoolean("worldguard.enabled");
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding");
@ -1106,6 +1088,7 @@ public class PlotMain extends JavaPlugin {
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.MAX_PLOTS = config.getInt("max_plots");
Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path");
}
public static void createConfiguration(PlotWorld plotworld) {

View File

@ -15,6 +15,7 @@ package com.intellectualcrafters.plot;
* @author Empire92
*/
public class Settings {
public static String SCHEMATIC_SAVE_PATH = "/var/www/schematics";
public static int MAX_PLOTS = 20;
/**
* WorldGuard region on claimed plots
@ -70,12 +71,6 @@ public class Settings {
public static boolean AUTO_UPDATE = false;
}
public static class Web {
public static boolean ENABLED = false;
public static int PORT = 9000;
public static String PATH = "/var/www";
}
/**
* Database settings
*

View File

@ -1,26 +1,13 @@
package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.*;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.SchematicHandler;
import com.intellectualcrafters.plot.Settings;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore;
import java.util.HashMap;
public class Schematic extends SubCommand {
@ -160,8 +147,7 @@ public class Schematic extends SubCommand {
@Override
public void run() {
PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id);
boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+", "+owner+".schematic");
boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+","+owner+".schematic");
if (!result) {
PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id);
}
@ -251,8 +237,7 @@ public class Schematic extends SubCommand {
@Override
public void run() {
PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id);
boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+world+","+owner+".schematic");
boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH+"/"+plot.id.x+","+plot.id.y+","+world+","+owner+".schematic");
if (!result) {
PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id);
}

View File

@ -359,10 +359,24 @@ public class Set extends SubCommand {
PlotHelper.adjustWallFilling(plr, plot, new PlotBlock((short) material.getId(), data));
return true;
}
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(values));
PlayerFunctions.sendMessage(plr, builder.toString());
{
AbstractFlag af = new AbstractFlag("");
try {
af = new AbstractFlag(args[0].toLowerCase());
}
catch (Exception e) {
}
if (FlagManager.getFlags().contains(af)) {
StringBuilder a = new StringBuilder();
if(args.length > 1) {
for(int x = 1; x < args.length; x++)
a.append(" ").append(args[x]);
}
plr.performCommand("plot set flag " + args[0] + a.toString());
return true;
}
}
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values));
return false;
}

View File

@ -175,6 +175,7 @@ public class PlotListener {
}
public static void plotExit(Player player, Plot plot) {
player.setAllowFlight(false);
{
PlayerLeavePlotEvent callEvent = new PlayerLeavePlotEvent(player, plot);
Bukkit.getPluginManager().callEvent(callEvent);

View File

@ -1,98 +0,0 @@
package com.intellectualsites.web;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.core.Container;
/**
* Created by Citymonstret on 2014-09-20.
*/
public class IndexHandler implements Container {
private JavaPlugin plugin;
private String title;
public IndexHandler(JavaPlugin plugin, String title) {
this.plugin = plugin;
this.title = title;
}
@Override
public void handle(Request request, Response response) {
try {
PrintStream body;
long time;
String coverage;
body = response.getPrintStream();
time = System.currentTimeMillis();
request.getQuery();
request.getPath();
if ((request.getInteger("page")) < 0) {
}
if (((coverage = request.getTarget()) == null) || coverage.equals("/")) {
coverage = "index";
}
coverage = coverage.toLowerCase();
List<String> list = new ArrayList<>(Arrays.asList(new String[] { "install", "index", "stylesheet" }));
if (!list.contains(coverage)) {
coverage = "index";
}
if (coverage.equals("stylesheet")) {
response.setValue("Content-Type", "text/css");
response.setValue("Server", "PlotWeb/1.0 (Simple 5.0)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
ResourceHandler stylesheet =
new ResourceHandler("stylesheet", ResourceHandler.FileType.CSS, this.plugin.getDataFolder());
String stylesheetHTML = stylesheet.getHTML();
stylesheet.done();
body.print(stylesheetHTML);
}
else {
response.setValue("Content-Type", "html");
response.setValue("Server", "PlotWeb/1.0 (Simple 5.0)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
ResourceHandler header =
new ResourceHandler("header", ResourceHandler.FileType.HTML, this.plugin.getDataFolder());
ResourceHandler footer =
new ResourceHandler("footer", ResourceHandler.FileType.HTML, this.plugin.getDataFolder());
ResourceHandler cPage =
new ResourceHandler(coverage, ResourceHandler.FileType.HTML, this.plugin.getDataFolder());
String headerHTML = header.getHTML().replace("@title", this.title);
String footerHTML = footer.getHTML();
String cPageHTML = cPage.getHTML();
header.done();
footer.done();
cPage.done();
body.print(headerHTML);
body.print(cPageHTML);
body.print(footerHTML);
}
body.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,50 +0,0 @@
package com.intellectualsites.web;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import org.bukkit.plugin.java.JavaPlugin;
import org.simpleframework.http.core.Container;
import org.simpleframework.http.core.ContainerServer;
import org.simpleframework.transport.Server;
import org.simpleframework.transport.connect.Connection;
import org.simpleframework.transport.connect.SocketConnection;
import com.intellectualcrafters.plot.PlotMain;
/**
* Created by Citymonstret on 2014-09-20.
*/
public class PlotWeb {
// TODO instructions on how to setup and use PlotWeb.
public static PlotWeb PLOTWEB;
private String title;
private int port;
private Server server;
private Connection connection;
private Container container;
private SocketAddress address;
public PlotWeb(String title, int port) {
this.title = title;
this.port = port;
}
public void start() throws Exception {
this.container = new IndexHandler(JavaPlugin.getPlugin(PlotMain.class), this.title);
this.server = new ContainerServer(this.container);
this.connection = new SocketConnection(this.server);
this.address = new InetSocketAddress(this.port);
this.connection.connect(this.address);
PLOTWEB = this;
}
public void stop() throws Exception {
this.connection.close();
PLOTWEB = null;
}
}

View File

@ -1,59 +0,0 @@
package com.intellectualsites.web;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
/**
* Created by Citymonstret on 2014-09-20.
*/
public class ResourceHandler {
private File file;
private BufferedReader reader;
public ResourceHandler(String filePath, FileType fileType, File folder) throws Exception {
if (fileType == FileType.CSS) {
this.file =
new File(folder.toPath().toString() + File.separator + "web" + File.separator + "css"
+ File.separator + filePath + "." + fileType.toString());
}
else {
this.file =
new File(folder.toPath().toString() + File.separator + "web" + File.separator + filePath + "."
+ fileType.toString());
}
}
public String getHTML() throws Exception {
StringBuilder html = new StringBuilder();
this.reader = new BufferedReader(new InputStreamReader(new FileInputStream(this.file)));
String line = "";
while ((line = this.reader.readLine()) != null) {
html.append(line);
}
return html.toString();
}
public void done() throws Exception {
this.reader.close();
}
public static enum FileType {
CSS("css"),
HTML("html"),
JS("js");
private String ext;
FileType(String ext) {
this.ext = ext;
}
@Override
public String toString() {
return this.ext;
}
}
}

View File

@ -1,17 +0,0 @@
package com.intellectualsites.web;
/**
* Created by Citymonstret on 2014-09-20.
*/
public class Test {
public static void main(String[] args) {
try {
new PlotWeb("Test", 9000).start();
}
catch (Exception e) {
e.printStackTrace();
}
}
}