diff options
author | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:33:18 +0200 |
---|---|---|
committer | Leonard Kugis <leonard@kug.is> | 2022-04-25 18:33:18 +0200 |
commit | 54b81b2dccd7cfa58e5bd5fe95a158126115381c (patch) | |
tree | 54496832d24749b710880bb342e514739b841155 /src/com |
Diffstat (limited to 'src/com')
-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 |
3 files changed, 376 insertions, 0 deletions
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;
+ }
+
+}
|