WorldGuard Support.

Fixed NullPointerException in C

Added Settings

Fixed tons of warning :P

Added auto clear
This commit is contained in:
Sauilitired 2014-09-24 20:29:30 +02:00
parent f56d6f144b
commit 0d0825d614
11 changed files with 654 additions and 629 deletions

View File

@ -1,8 +0,0 @@
<component name="ArtifactManager">
<artifact type="jar" build-on-make="true" name="plotsquared__">
<output-path>$PROJECT_DIR$/out/plotsquared</output-path>
<root id="archive" name="plotsquared__.jar">
<element id="module-output" name="PlotSquared" />
</root>
</artifact>
</component>

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="WorldGuard">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/WorldGuard.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@
<orderEntry type="library" name="bukkit-1.7.9-R0.2" level="project" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="simple-xml" level="project" />
<orderEntry type="library" name="WorldGuard" level="project" />
</component>
</module>

View File

@ -185,7 +185,11 @@ public enum C {
*/
C(String d) {
this.d = d;
if(PlotMain.translations == null) {
this.s = d;
} else {
this.s = PlotMain.translations.getString(this.toString());
}
if (this.s == null) {
this.s = "";
}

View File

@ -9,126 +9,7 @@
package com.intellectualcrafters.plot;
import static org.bukkit.Material.ACACIA_STAIRS;
import static org.bukkit.Material.BEACON;
import static org.bukkit.Material.BEDROCK;
import static org.bukkit.Material.BIRCH_WOOD_STAIRS;
import static org.bukkit.Material.BOOKSHELF;
import static org.bukkit.Material.BREWING_STAND;
import static org.bukkit.Material.BRICK;
import static org.bukkit.Material.BRICK_STAIRS;
import static org.bukkit.Material.BURNING_FURNACE;
import static org.bukkit.Material.CAKE_BLOCK;
import static org.bukkit.Material.CAULDRON;
import static org.bukkit.Material.CLAY;
import static org.bukkit.Material.CLAY_BRICK;
import static org.bukkit.Material.COAL_BLOCK;
import static org.bukkit.Material.COAL_ORE;
import static org.bukkit.Material.COBBLESTONE;
import static org.bukkit.Material.COBBLESTONE_STAIRS;
import static org.bukkit.Material.COBBLE_WALL;
import static org.bukkit.Material.COMMAND;
import static org.bukkit.Material.DARK_OAK_STAIRS;
import static org.bukkit.Material.DAYLIGHT_DETECTOR;
import static org.bukkit.Material.DIAMOND_BLOCK;
import static org.bukkit.Material.DIAMOND_ORE;
import static org.bukkit.Material.DIRT;
import static org.bukkit.Material.DISPENSER;
import static org.bukkit.Material.DROPPER;
import static org.bukkit.Material.EMERALD_BLOCK;
import static org.bukkit.Material.EMERALD_ORE;
import static org.bukkit.Material.ENCHANTMENT_TABLE;
import static org.bukkit.Material.ENDER_PORTAL_FRAME;
import static org.bukkit.Material.ENDER_STONE;
import static org.bukkit.Material.FURNACE;
import static org.bukkit.Material.GLASS;
import static org.bukkit.Material.GLOWSTONE;
import static org.bukkit.Material.GOLD_BLOCK;
import static org.bukkit.Material.GOLD_ORE;
import static org.bukkit.Material.GRASS;
import static org.bukkit.Material.GRAVEL;
import static org.bukkit.Material.HARD_CLAY;
import static org.bukkit.Material.HAY_BLOCK;
import static org.bukkit.Material.HUGE_MUSHROOM_1;
import static org.bukkit.Material.HUGE_MUSHROOM_2;
import static org.bukkit.Material.IRON_BLOCK;
import static org.bukkit.Material.IRON_ORE;
import static org.bukkit.Material.JACK_O_LANTERN;
import static org.bukkit.Material.JUKEBOX;
import static org.bukkit.Material.JUNGLE_WOOD_STAIRS;
import static org.bukkit.Material.LAPIS_BLOCK;
import static org.bukkit.Material.LAPIS_ORE;
import static org.bukkit.Material.LEAVES;
import static org.bukkit.Material.LEAVES_2;
import static org.bukkit.Material.LOG;
import static org.bukkit.Material.LOG_2;
import static org.bukkit.Material.MELON_BLOCK;
import static org.bukkit.Material.MOB_SPAWNER;
import static org.bukkit.Material.MOSSY_COBBLESTONE;
import static org.bukkit.Material.MYCEL;
import static org.bukkit.Material.NETHERRACK;
import static org.bukkit.Material.NETHER_BRICK;
import static org.bukkit.Material.NETHER_BRICK_STAIRS;
import static org.bukkit.Material.NOTE_BLOCK;
import static org.bukkit.Material.OBSIDIAN;
import static org.bukkit.Material.PACKED_ICE;
import static org.bukkit.Material.PUMPKIN;
import static org.bukkit.Material.QUARTZ_BLOCK;
import static org.bukkit.Material.QUARTZ_ORE;
import static org.bukkit.Material.QUARTZ_STAIRS;
import static org.bukkit.Material.REDSTONE_BLOCK;
import static org.bukkit.Material.SAND;
import static org.bukkit.Material.SANDSTONE;
import static org.bukkit.Material.SANDSTONE_STAIRS;
import static org.bukkit.Material.SMOOTH_BRICK;
import static org.bukkit.Material.SMOOTH_STAIRS;
import static org.bukkit.Material.SNOW_BLOCK;
import static org.bukkit.Material.SOUL_SAND;
import static org.bukkit.Material.SPONGE;
import static org.bukkit.Material.SPRUCE_WOOD_STAIRS;
import static org.bukkit.Material.STONE;
import static org.bukkit.Material.WOOD;
import static org.bukkit.Material.WOOD_STAIRS;
import static org.bukkit.Material.WOOL;
import static org.bukkit.Material.WORKBENCH;
import static org.bukkit.Material.getMaterial;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import me.confuser.barapi.BarAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin;
import ca.mera.CameraAPI;
import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.Settings.Web;
import com.intellectualcrafters.plot.commands.Camera;
@ -141,7 +22,27 @@ import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.listeners.PlayerEvents;
import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldGuardListener;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import me.confuser.barapi.BarAPI;
import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.*;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.Map.Entry;
import static org.bukkit.Material.*;
/**
* @awesome @author Citymonstret, Empire92 PlotMain class.
@ -191,6 +92,9 @@ public class PlotMain extends JavaPlugin {
*/
public static CameraAPI cameraAPI;
public static WorldGuardPlugin worldGuard;
/**
* !!WorldGeneration!!
*/
@ -410,7 +314,10 @@ public class PlotMain extends JavaPlugin {
if (plot.owner == null) {
continue;
}
if (PlayerFunctions.hasExpired(plot)) {
long lastPlayed = getLastPlayed(plot.owner);
if(lastPlayed == 0) continue;
int days = (int) (lastPlayed / (1000*60*60*24));
if (days >= Settings.AUTO_CLEAR_DAYS) {
PlotDeleteEvent event = new PlotDeleteEvent(world, plot.id);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
@ -561,6 +468,7 @@ public class PlotMain extends JavaPlugin {
e.printStackTrace();
}
}
getCommand("plots").setExecutor(new MainCommand());
getCommand("plots").setAliases(new ArrayList<String>() {
{
@ -569,6 +477,7 @@ public class PlotMain extends JavaPlugin {
add("plot");
}
});
getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
if (getServer().getPluginManager().getPlugin("CameraAPI") != null) {
@ -584,13 +493,19 @@ public class PlotMain extends JavaPlugin {
worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
}
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard");
getServer().getPluginManager().registerEvents(new WorldGuardListener(this), this);
}
if(Settings.AUTO_CLEAR) {
checkExpired(PlotMain.getMain(), true);
checkForExpiredPlots();
}
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Lag(), 100L, 1L);
if (Web.ENABLED) {
sendConsoleSenderMessage(C.PREFIX.s() + "This is not yet implemented...");
sendConsoleSenderMessage(C.PREFIX.s() + "Web Is not implemented yet. Please bear with us.");
}
}
@ -702,6 +617,14 @@ public class PlotMain extends JavaPlugin {
translations = YamlConfiguration.loadConfiguration(translationsFile);
}
public static long getLastPlayed(UUID uuid) {
if(uuid == null) return 0;
OfflinePlayer player;
if((player = Bukkit.getOfflinePlayer(uuid)) == null || !player.hasPlayedBefore()) {
return 0;
}
return player.getLastPlayed();
}
/**
* Load configuration files
*/
@ -768,6 +691,24 @@ public class PlotMain extends JavaPlugin {
// Web
// Web.ENABLED = config.getBoolean("web.enabled");
// Web.PORT = config.getInt("web.port");
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
}
if(Settings.DEBUG) {
Map<String, String> settings = new HashMap<>();
settings.put("Kill Road Mobs", "" + Settings.KILL_ROAD_MOBS);
settings.put("Use Metrics", "" + Settings.METRICS);
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);
for(Entry<String, String> setting : settings.entrySet()) {
sendConsoleSenderMessage(C.PREFIX.s() + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue()));
}
}
}
@ -888,11 +829,19 @@ public class PlotMain extends JavaPlugin {
options.put("web.enabled", Web.ENABLED);
options.put("web.port", Web.PORT);
options.put("metrics", true);
options.put("debug", true);
options.put("clear.auto.enabled", false);
options.put("clear.auto.days", 365);
for (Entry<String, Object> node : options.entrySet()) {
if (!config.contains(node.getKey())) {
config.set(node.getKey(), node.getValue());
}
}
Settings.DEBUG = config.getBoolean("debug");
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");
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");

View File

@ -46,6 +46,11 @@ public class Settings {
*/
public static String URL = "http://dev.bukkit.org/bukkit-plugins/plotsquared/";
public static boolean DEBUG = true;
public static boolean AUTO_CLEAR = false;
public static int AUTO_CLEAR_DAYS = 365;
public static class Update {
/**
* Update plugin?

View File

@ -1,30 +1,5 @@
package com.intellectualcrafters.plot;
import static com.intellectualcrafters.plot.PlotWorld.DEFAULT_FLAGS_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.MAIN_BLOCK_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.PLOT_BIOME_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.PLOT_HEIGHT_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.PLOT_WIDTH_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.ROAD_BLOCK_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.ROAD_HEIGHT_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.ROAD_WIDTH_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_FILE_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.SCHEMATIC_ON_CLAIM_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.TOP_BLOCK_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.WALL_BLOCK_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.WALL_FILLING_DEFAULT;
import static com.intellectualcrafters.plot.PlotWorld.WALL_HEIGHT_DEFAULT;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -33,6 +8,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
import static com.intellectualcrafters.plot.PlotWorld.*;
/**
* TODO finish recoding this class
*
@ -40,6 +21,7 @@ import org.bukkit.generator.ChunkGenerator;
* @author Citymonstret
*
*/
@SuppressWarnings("deprecation")
public class WorldGenerator extends ChunkGenerator {
private long state;

View File

@ -9,17 +9,16 @@
package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Visit extends SubCommand {
public Visit() {
@ -27,7 +26,7 @@ public class Visit extends SubCommand {
}
public List<Plot> getPlots(UUID uuid) {
List<Plot> plots = new ArrayList<Plot>();
List<Plot> plots = new ArrayList<>();
for (Plot p : PlotMain.getPlots()) {
if (p.owner.equals(uuid)) {
plots.add(p);
@ -36,6 +35,7 @@ public class Visit extends SubCommand {
return plots;
}
@SuppressWarnings("deprecation")
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {

View File

@ -0,0 +1,62 @@
package com.intellectualcrafters.plot.listeners;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* Created by Citymonstret on 2014-09-24.
*/
public class WorldGuardListener implements Listener {
private PlotMain plugin;
public WorldGuardListener(PlotMain plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onPlotClaim(PlayerClaimPlotEvent event) {
Player player = event.getPlayer();
Plot plot = event.getPlot();
RegionManager manager = PlotMain.worldGuard.getRegionManager(plot.getWorld());
Location location1 = PlotHelper.getPlotBottomLoc(plot.getWorld(), plot.getId());
Location location2 = PlotHelper.getPlotTopLoc(plot.getWorld(), plot.getId());
BlockVector vector1 = new BlockVector(location1.getBlockX(), 1, location1.getBlockZ());
BlockVector vector2 = new BlockVector(location2.getBlockX(), plot.getWorld().getMaxHeight(), location2.getBlockZ());
ProtectedRegion region = new ProtectedCuboidRegion(plot.getId().x + ";" + plot.getId().y, vector1, vector2);
DefaultDomain owner = new DefaultDomain();
owner.addPlayer(PlotMain.worldGuard.wrapPlayer(player));
region.setOwners(owner);
manager.addRegion(region);
}
@EventHandler
public void onPlotDelete(PlotDeleteEvent event) {
PlotId plot = event.getPlotId();
World world = Bukkit.getWorld(event.getWorld());
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
manager.removeRegion(plot.x + ";" + plot.y);
}
}

View File

@ -123,7 +123,97 @@
<!-- Modules -->
<import file="${basedir}/PlotSquared/module_plotsquared.xml"/>
<!-- Module PlotSquared -->
<dirname property="module.plotsquared.basedir" file="${ant.file}"/>
<property name="module.jdk.home.plotsquared" value="${project.jdk.home}"/>
<property name="module.jdk.bin.plotsquared" value="${project.jdk.bin}"/>
<property name="module.jdk.classpath.plotsquared" value="${project.jdk.classpath}"/>
<property name="compiler.args.plotsquared" value="-encoding UTF-8 -source 1.7 ${compiler.args}"/>
<property name="plotsquared.output.dir" value="${module.plotsquared.basedir}/out/production/PlotSquared"/>
<property name="plotsquared.testoutput.dir" value="${module.plotsquared.basedir}/out/test/PlotSquared"/>
<path id="plotsquared.module.bootclasspath">
<!-- Paths to be included in compilation bootclasspath -->
</path>
<path id="plotsquared.module.production.classpath">
<path refid="${module.jdk.classpath.plotsquared}"/>
<path refid="library.bukkit-1.7.9-r0.2.classpath"/>
<path refid="library.lib.classpath"/>
<path refid="library.simple-xml.classpath"/>
</path>
<path id="plotsquared.runtime.production.module.classpath">
<pathelement location="${plotsquared.output.dir}"/>
<path refid="library.bukkit-1.7.9-r0.2.classpath"/>
<path refid="library.lib.classpath"/>
<path refid="library.simple-xml.classpath"/>
</path>
<path id="plotsquared.module.classpath">
<path refid="${module.jdk.classpath.plotsquared}"/>
<pathelement location="${plotsquared.output.dir}"/>
<path refid="library.bukkit-1.7.9-r0.2.classpath"/>
<path refid="library.lib.classpath"/>
<path refid="library.simple-xml.classpath"/>
</path>
<path id="plotsquared.runtime.module.classpath">
<pathelement location="${plotsquared.testoutput.dir}"/>
<pathelement location="${plotsquared.output.dir}"/>
<path refid="library.bukkit-1.7.9-r0.2.classpath"/>
<path refid="library.lib.classpath"/>
<path refid="library.simple-xml.classpath"/>
</path>
<patternset id="excluded.from.module.plotsquared">
<patternset refid="ignored.files"/>
</patternset>
<patternset id="excluded.from.compilation.plotsquared">
<patternset refid="excluded.from.module.plotsquared"/>
</patternset>
<path id="plotsquared.module.sourcepath">
<dirset dir="${module.plotsquared.basedir}/PlotSquared">
<include name="src"/>
</dirset>
</path>
<target name="compile.module.plotsquared" depends="compile.module.plotsquared.production,compile.module.plotsquared.tests" description="Compile module PlotSquared"/>
<target name="compile.module.plotsquared.production" depends="register.custom.compilers" description="Compile module PlotSquared; production classes">
<mkdir dir="${plotsquared.output.dir}"/>
<javac2 destdir="${plotsquared.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.plotsquared}/javac">
<compilerarg line="${compiler.args.plotsquared}"/>
<bootclasspath refid="plotsquared.module.bootclasspath"/>
<classpath refid="plotsquared.module.production.classpath"/>
<src refid="plotsquared.module.sourcepath"/>
<patternset refid="excluded.from.compilation.plotsquared"/>
</javac2>
<copy todir="${plotsquared.output.dir}">
<fileset dir="${module.plotsquared.basedir}/PlotSquared/src">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target>
<target name="compile.module.plotsquared.tests" depends="register.custom.compilers,compile.module.plotsquared.production" description="compile module PlotSquared; test classes" unless="skip.tests"/>
<target name="clean.module.plotsquared" description="cleanup module">
<delete dir="${plotsquared.output.dir}"/>
<delete dir="${plotsquared.testoutput.dir}"/>
</target>
<target name="init" description="Build initialization">
<!-- Perform any build initialization in this target -->