diff options
-rwxr-xr-x | .classpath | 10 | ||||
-rw-r--r-- | .gitignore | 171 | ||||
-rwxr-xr-x | .project | 17 | ||||
-rwxr-xr-x | plugin.yml | 8 | ||||
-rwxr-xr-x | src/com/encrox/cplot/Core.java | 65 | ||||
-rwxr-xr-x | src/com/encrox/cplot/command/Gs.java | 281 | ||||
-rwxr-xr-x | src/com/encrox/cplot/constants/Direction.java | 30 |
7 files changed, 582 insertions, 0 deletions
diff --git a/.classpath b/.classpath new file mode 100755 index 0000000..44e3875 --- /dev/null +++ b/.classpath @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="lib" path="craftbukkit-1.8.8.jar"/>
+ <classpathentry kind="lib" path="Essentials.jar"/>
+ <classpathentry kind="lib" path="worldguard-6.1.jar"/>
+ <classpathentry kind="lib" path="worldedit-bukkit-6.1.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d02df8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,171 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/eclipse,java,windows,linux,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,java,windows,linux,macos + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/eclipse,java,windows,linux,macos diff --git a/.project b/.project new file mode 100755 index 0000000..d0c06e9 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>cplot</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugin.yml b/plugin.yml new file mode 100755 index 0000000..51a88dc --- /dev/null +++ b/plugin.yml @@ -0,0 +1,8 @@ +main: com.encrox.cplot.Core
+name: CPlot
+version: 1.0
+
+commands:
+ gs:
+ description: Manages plot claiming.
+ usage: /gs help
\ No newline at end of file diff --git a/src/com/encrox/cplot/Core.java b/src/com/encrox/cplot/Core.java new file mode 100755 index 0000000..4d361c7 --- /dev/null +++ b/src/com/encrox/cplot/Core.java @@ -0,0 +1,65 @@ +package com.encrox.cplot;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.RegisteredServiceProvider;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import com.earth2me.essentials.api.Economy;
+import com.encrox.cplot.command.Gs;
+import com.sk89q.worldedit.bukkit.WorldEditPlugin;
+import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
+
+public class Core extends JavaPlugin {
+
+ public static Logger logger;
+ public static PluginDescriptionFile pdf;
+ public static WorldGuardPlugin wg;
+ public static WorldEditPlugin we;
+ public static Properties p;
+
+ public void onEnable() {
+ pdf = getDescription();
+ logger = Logger.getLogger("Minecraft");
+ if(setupMyself() && setupWorldGuard()) {
+ getCommand("gs").setExecutor(new Gs());
+ logger.info(pdf.getName() + " " + pdf.getVersion() + " has been enabled.");
+ } else {
+ logger.info(pdf.getName() + " " + pdf.getVersion() + " has been disabled.");
+ }
+ }
+
+ public boolean setupWorldGuard() {
+ wg = (WorldGuardPlugin) Bukkit.getPluginManager().getPlugin("WorldGuard");
+ we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
+ return (wg != null) && (we != null);
+ }
+
+ public boolean setupMyself() {
+ if(!this.getDataFolder().exists())
+ this.getDataFolder().mkdirs();
+ p = new Properties();
+ try {
+ p.load(new FileReader(new File(this.getDataFolder() + "/config.properties")));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ public void onDisable() {
+ logger.info(pdf.getName() + " " + pdf.getVersion() + " has been disabled.");
+ }
+
+}
diff --git a/src/com/encrox/cplot/command/Gs.java b/src/com/encrox/cplot/command/Gs.java new file mode 100755 index 0000000..3ec843e --- /dev/null +++ b/src/com/encrox/cplot/command/Gs.java @@ -0,0 +1,281 @@ +package com.encrox.cplot.command;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.earth2me.essentials.OfflinePlayer;
+import com.earth2me.essentials.api.Economy;
+import com.encrox.cplot.Core;
+import com.encrox.cplot.constants.Direction;
+import com.sk89q.worldedit.BlockVector;
+import com.sk89q.worldedit.bukkit.selections.Selection;
+import com.sk89q.worldguard.LocalPlayer;
+import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
+
+public class Gs implements CommandExecutor {
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ try {
+ if(sender instanceof Player) {
+ Player player = (Player)sender;
+ if(sender.hasPermission("cplot.gs." + player.getWorld().getName())) {
+ switch(args[0]) {
+ case "claim":
+ switch(args.length) {
+ case 2:
+ Selection sel = Core.we.getSelection((Player)sender);
+ if(sel == null) {
+ sender.sendMessage(ChatColor.RED + "No selection made. Please make a selection with the wand-tool first.");
+ return false;
+ }
+ Location min = sel.getMinimumPoint(), max = sel.getMaximumPoint();
+ return claim(player, args[1], min.getBlockX(), min.getBlockY(), min.getBlockZ(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
+ case 6:
+ return claim(player, args[1], Integer.parseInt(args[2]), 0, Integer.parseInt(args[3]), Integer.parseInt(args[4]), 255, Integer.parseInt(args[5]));
+ case 8:
+ return claim(player, args[1], Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), Integer.parseInt(args[7]));
+ }
+ case "expand":
+ return expand(player, args[1], Direction.getDirection(args[2]), Integer.parseInt(args[3]));
+ case "unclaim":
+ switch(args.length) {
+ case 2:
+ return unclaim(player, args[1]);
+ case 3:
+ if(player.hasPermission("cplot.admin")) {
+ String regionName = Bukkit.getServer().getOfflinePlayer(args[1]).getUniqueId().toString() + "_" + args[2];
+ if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
+ Core.wg.getRegionManager(player.getWorld()).removeRegion(regionName);
+ }
+ player.sendMessage(ChatColor.GREEN + "Region has been unclaimed.");
+ return true;
+ } else {
+ player.sendMessage(ChatColor.RED + "You dont have permission to perform this command.");
+ return false;
+ }
+ }
+ case "add":
+ return add(player, args[1], args[2]);
+ case "remove":
+ return remove(player, args[1], args[2]);
+ case "op":
+ return op(player, args[1], args[2]);
+ case "deop":
+ return deop(player, args[1], args[2]);
+ case "price":
+ return price(player);
+ case "help":
+ player.sendMessage(ChatColor.YELLOW + "/gs claim <name> [<x1> [<y1>] <z1> <x2> [<y2>] <z2>]\n" + ChatColor.WHITE + "Claims a new plot with the name <name> from pos1 to pos2.\n" +
+ ChatColor.YELLOW + "/gs expand <name> <north/south/east/west/up/down> <length>\n" + ChatColor.WHITE + "Expands the plot with the name <name> in a specific direction by <length>.\n" +
+ ChatColor.YELLOW + "/gs unclaim <name>\n" + ChatColor.WHITE + "Unclaims the plot with the name <name>.\n" +
+ ChatColor.YELLOW + "/gs add/remove <name> <player>\n" + ChatColor.WHITE + "Adds/Removes the player <player> to/from the members list of the plot with the name <name>.\n" +
+ ChatColor.YELLOW + "/gs op/deop <name> <player>\n" + ChatColor.WHITE + "Adds/Removes the player <player> to/from the members list of the plot with the name <name>.\n" +
+ ChatColor.YELLOW + "/gs price\n" + ChatColor.WHITE + "Shows the price/block in the current world.");
+ return true;
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "You dont have permissions to perform this command.");
+ }
+ } else {
+ sender.sendMessage("This can only be issued by a player.");
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ private boolean claim(Player player, String label, int x1, int y1, int z1, int x2, int y2, int z2) {
+ String regionName = player.getUniqueId().toString() + "_" + label;
+ double cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (x2-x1) * (y2-y1) * (z2-z1);
+ try {
+ if(Economy.hasEnough(player.getName(), cost)) {
+ if(!Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
+ ProtectedCuboidRegion region = new ProtectedCuboidRegion(regionName, new BlockVector(x1, y1, z1), new BlockVector(x2, y2, z2));
+ if(region.getIntersectingRegions(Core.wg.getRegionManager(player.getWorld()).getRegions().values()).size() == 0) {
+ Economy.subtract(player.getName(), cost);
+ Core.wg.getRegionManager(player.getWorld()).addRegion(region);
+ Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().addPlayer(player.getUniqueId());
+ player.sendMessage(ChatColor.GREEN + "Region claimed for " + ChatColor.GOLD + cost);
+ } else {
+ player.sendMessage(ChatColor.RED + "Region already claimed / Intersecting with another region.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Name already taken.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Not enough money! You need " + ChatColor.GOLD + cost);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ private boolean expand(Player player, String label, byte direction, int size) {
+ String regionName = player.getUniqueId().toString() + "_" + label;
+ double cost = 0.0;
+ int x1, y1, z1, x2, y2, z2;
+ BlockVector min, max;
+ ProtectedCuboidRegion region = (ProtectedCuboidRegion) Core.wg.getRegionManager(player.getWorld()).getRegion(regionName);
+ if(region != null) {
+ min = region.getMinimumPoint();
+ max = region.getMaximumPoint();
+ x1 = min.getBlockX();
+ y1 = min.getBlockY();
+ z1 = min.getBlockZ();
+ x2 = max.getBlockX();
+ y2 = max.getBlockY();
+ z2 = max.getBlockZ();
+ Core.wg.getRegionManager(player.getWorld()).removeRegion(regionName);
+ try {
+ switch(direction) {
+ case Direction.NORTH:
+ cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
+ z1-=size;
+ break;
+ case Direction.SOUTH:
+ cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
+ z2+=size;
+ break;
+ case Direction.EAST:
+ cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
+ x2+=size;
+ break;
+ case Direction.WEST:
+ cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
+ x1-=size;
+ break;
+ case Direction.UP:
+ cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
+ y2+=size;
+ break;
+ case Direction.DOWN:
+ cost = Double.parseDouble(Core.p.getProperty(player.getWorld().getName() + "_price")) * (max.getBlockX()-min.getBlockX()) * (max.getBlockY()-min.getBlockY()) * size;
+ y1-=size;
+ break;
+ }
+ if(Economy.hasEnough(player.getName(), cost)) {
+ ProtectedCuboidRegion newRegion = new ProtectedCuboidRegion(regionName, new BlockVector(x1, y1, z1), new BlockVector(x2, y2, z2));
+ if(newRegion.getIntersectingRegions(Core.wg.getRegionManager(player.getWorld()).getRegions().values()).size() == 0) {
+ Economy.subtract(player.getName(), cost);
+ Core.wg.getRegionManager(player.getWorld()).addRegion(newRegion);
+ Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().addPlayer(player.getUniqueId());
+ player.sendMessage(ChatColor.GREEN + "Region has been expanded for " + ChatColor.GOLD + cost);
+ } else {
+ player.sendMessage(ChatColor.RED + "Region already claimed / Intersecting with another region.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Not enough money for expansion. You need " + ChatColor.GOLD + cost);
+ }
+ return true;
+ } catch(Exception e) {
+ player.sendMessage(ChatColor.RED + "Something, regarding to economy, went wrong.");
+ }
+ }
+ return false;
+ }
+
+ private boolean unclaim(Player player, String label) {
+ String regionName = player.getUniqueId().toString() + "_" + label;
+ if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
+ LocalPlayer lp = Core.wg.wrapPlayer(player);
+ if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
+ Core.wg.getRegionManager(player.getWorld()).removeRegion(regionName);
+ player.sendMessage(ChatColor.GREEN + "Plot has been unclaimed.");
+ return true;
+ } else {
+ player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Region not found.");
+ }
+ return false;
+ }
+
+ private boolean add(Player player, String label, String addPlayer) {
+ String regionName = player.getUniqueId().toString() + "_" + label;
+ if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
+ LocalPlayer lp = Core.wg.wrapPlayer(player);
+ if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
+ Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getMembers().addPlayer(addPlayer);
+ player.sendMessage(ChatColor.GREEN + "Player has been added.");
+ return true;
+ } else {
+ player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Region not found.");
+ }
+ return false;
+ }
+
+ private boolean remove(Player player, String label, String removePlayer) {
+ String regionName = player.getUniqueId().toString() + "_" + label;
+ if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
+ LocalPlayer lp = Core.wg.wrapPlayer(player);
+ if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
+ Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getMembers().removePlayer(removePlayer);
+ player.sendMessage(ChatColor.GREEN + "Player has been removed.");
+ return true;
+ } else {
+ player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Region not found.");
+ }
+ return false;
+ }
+
+ private boolean op(Player player, String label, String addPlayer) {
+ String regionName = player.getUniqueId().toString() + "_" + label;
+ if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
+ LocalPlayer lp = Core.wg.wrapPlayer(player);
+ if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
+ Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().addPlayer(addPlayer);
+ player.sendMessage(ChatColor.GREEN + "Player has been added.");
+ return true;
+ } else {
+ player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Region not found.");
+ }
+ return false;
+ }
+
+ private boolean deop(Player player, String label, String removePlayer) {
+ String regionName = player.getUniqueId().toString() + "_" + label;
+ if(Core.wg.getRegionManager(player.getWorld()).hasRegion(regionName)) {
+ LocalPlayer lp = Core.wg.wrapPlayer(player);
+ if(Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).isOwner(lp)) {
+ Core.wg.getRegionManager(player.getWorld()).getRegion(regionName).getOwners().removePlayer(removePlayer);
+ player.sendMessage(ChatColor.GREEN + "Player has been removed.");
+ return true;
+ } else {
+ player.sendMessage(ChatColor.RED + "You are not the owner of this region.");
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "Region not found.");
+ }
+ return false;
+ }
+
+ private boolean price(Player player) {
+ String world = player.getWorld().getName();
+ player.sendMessage(ChatColor.GREEN + "Price/block in world " + world + ": " + ChatColor.GOLD + Core.p.getProperty(world + "_price"));
+ return true;
+ }
+
+}
diff --git a/src/com/encrox/cplot/constants/Direction.java b/src/com/encrox/cplot/constants/Direction.java new file mode 100755 index 0000000..11b1932 --- /dev/null +++ b/src/com/encrox/cplot/constants/Direction.java @@ -0,0 +1,30 @@ +package com.encrox.cplot.constants;
+
+public class Direction {
+
+ public static final byte NORTH = 0;
+ public static final byte SOUTH = 1;
+ public static final byte EAST = 2;
+ public static final byte WEST = 3;
+ public static final byte UP = 4;
+ public static final byte DOWN = 5;
+
+ public static byte getDirection(String label) {
+ switch(label.toLowerCase()) {
+ case "north":
+ return NORTH;
+ case "south":
+ return SOUTH;
+ case "east":
+ return EAST;
+ case "west":
+ return WEST;
+ case "up":
+ return UP;
+ case "down":
+ return DOWN;
+ }
+ return -1;
+ }
+
+}
|