mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 20:56:45 +01:00
Economy Support (Stage 1, alpha xD)
Added schematic support for Auto Continued working on setup command Made sexy exception thingy Tried to fix Errors in PWE Added some epic captions Added configuration options to PlotWorld YAY
This commit is contained in:
parent
c5195fc198
commit
b28c44b0df
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,12 @@ import org.bukkit.ChatColor;
|
||||
*
|
||||
*/
|
||||
public enum C {
|
||||
/**
|
||||
* Economy Stuff
|
||||
*/
|
||||
CANNOT_AFFORD_PLOT("&cYou cannot afford to buy this plot. It costs &6%s"),
|
||||
CANNOT_AFFORD_MERGE("&cYou cannot afford to merge the plots. It costs &6%s"),
|
||||
REMOVED_BALANCE("&6%s &chas been taken from your balance"),
|
||||
/*
|
||||
* Setup Stuff
|
||||
*/
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldedit.masks.RegionMask;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
@ -18,47 +16,62 @@ import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
*/
|
||||
public class PWE {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void setMask(Player p, Location l) {
|
||||
LocalSession s = PlotMain.worldEdit.getSession(p);
|
||||
Plot plot = PlayerFunctions.getCurrentPlot(p);
|
||||
if (plot != null) {
|
||||
boolean r;
|
||||
if (plot.getOwner() != null) {
|
||||
r = plot.getOwner().equals(p.getUniqueId());
|
||||
try {
|
||||
LocalSession s;
|
||||
if (PlotMain.worldEdit == null) {
|
||||
s = WorldEdit.getInstance().getSession(p.getName());
|
||||
} else {
|
||||
r = false;
|
||||
s = PlotMain.worldEdit.getSession(p);
|
||||
}
|
||||
if (!r) {
|
||||
if (p.hasPermission("plots.we.member") && plot.hasRights(p)) {
|
||||
r = true;
|
||||
} else if (p.hasPermission("plots.we.bypass")) {
|
||||
s.setMask(null);
|
||||
Plot plot = PlayerFunctions.getCurrentPlot(p);
|
||||
if (plot != null) {
|
||||
boolean r;
|
||||
r = plot.getOwner() != null && plot.getOwner().equals(p.getUniqueId());
|
||||
if (!r) {
|
||||
if (p.hasPermission("plots.we.member") && plot.hasRights(p)) {
|
||||
r = true;
|
||||
} else if (p.hasPermission("plots.we.bypass")) {
|
||||
s.setMask(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (r) {
|
||||
World w = p.getWorld();
|
||||
Location b = PlotHelper.getPlotBottomLoc(w, plot.id);
|
||||
Location t = PlotHelper.getPlotTopLoc(w, plot.id);
|
||||
Vector p1 = new Vector(b.getBlockX(), b.getBlockY(), b.getBlockZ());
|
||||
Vector p2 = new Vector(t.getBlockX(), t.getBlockY(), t.getBlockZ());
|
||||
LocalWorld world = PlotMain.worldEdit.wrapPlayer(p).getWorld();
|
||||
CuboidRegion cr = new CuboidRegion(world, p1, p2);
|
||||
RegionMask rm = new RegionMask(cr);
|
||||
s.setMask(rm);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (r) {
|
||||
World w = p.getWorld();
|
||||
Location b = PlotHelper.getPlotBottomLoc(w, plot.id);
|
||||
Location t = PlotHelper.getPlotTopLoc(w, plot.id);
|
||||
Vector p1 = new Vector(b.getBlockX(), b.getBlockY(), b.getBlockZ());
|
||||
Vector p2 = new Vector(t.getBlockX(), t.getBlockY(), t.getBlockZ());
|
||||
LocalWorld world = PlotMain.worldEdit.wrapPlayer(p).getWorld();
|
||||
CuboidRegion cr = new CuboidRegion(world, p1, p2);
|
||||
RegionMask rm = new RegionMask(cr);
|
||||
s.setMask(rm);
|
||||
return;
|
||||
if (s.getMask() == null) {
|
||||
BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p);
|
||||
LocalWorld world = plr.getWorld();
|
||||
Vector p1 = new Vector(0, 0, 0), p2 = new Vector(0, 0, 0);
|
||||
s.setMask(new RegionMask(new CuboidRegion(world, p1, p2)));
|
||||
}
|
||||
}
|
||||
if (s.getMask() == null) {
|
||||
BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p);
|
||||
LocalWorld world = plr.getWorld();
|
||||
Vector p1 = new Vector(0, 0, 0), p2 = new Vector(0, 0, 0);
|
||||
s.setMask(new RegionMask(new CuboidRegion(world, p1, p2)));
|
||||
} catch(Exception e) {
|
||||
throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?");
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeMask(Player p) {
|
||||
LocalSession s = PlotMain.worldEdit.getSession(p);
|
||||
s.setMask(null);
|
||||
try {
|
||||
LocalSession s;
|
||||
if(PlotMain.worldEdit == null) {
|
||||
s = WorldEdit.getInstance().getSession(p.getName());
|
||||
} else {
|
||||
s = PlotMain.worldEdit.getSession(p);
|
||||
}
|
||||
s.setMask(null);
|
||||
} catch(Exception e) {
|
||||
throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
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;
|
||||
@ -26,15 +25,16 @@ 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 net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
@ -95,6 +95,9 @@ public class PlotMain extends JavaPlugin {
|
||||
|
||||
public static WorldGuardPlugin worldGuard;
|
||||
|
||||
public static Economy economy;
|
||||
public static boolean useEconomy;
|
||||
|
||||
/**
|
||||
* !!WorldGeneration!!
|
||||
*/
|
||||
@ -545,7 +548,13 @@ public class PlotMain extends JavaPlugin {
|
||||
checkExpired(PlotMain.getMain(), true);
|
||||
checkForExpiredPlots();
|
||||
}
|
||||
|
||||
if(getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if(economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
useEconomy = (economy != null);
|
||||
}
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Lag(), 100L, 1L);
|
||||
|
||||
if (Web.ENABLED) {
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-09-29.
|
||||
*/
|
||||
public class PlotSquaredException extends RuntimeException {
|
||||
|
||||
public PlotSquaredException(PlotError error, String details) {
|
||||
super("PlotError >> " + error.getHeader() + ": " + details);
|
||||
PlotMain.sendConsoleSenderMessage("&cPlotError &6>> &c" + error.getHeader() + ": &6" + details);
|
||||
}
|
||||
|
||||
public static enum PlotError {
|
||||
MISSING_DEPENDENCY("Missing Dependency")
|
||||
;
|
||||
private String errorHeader;
|
||||
PlotError(String errorHeader) {
|
||||
this.errorHeader = errorHeader;
|
||||
}
|
||||
|
||||
public String getHeader() {
|
||||
return this.errorHeader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getHeader();
|
||||
}
|
||||
}
|
||||
}
|
@ -210,4 +210,8 @@ public class PlotWorld {
|
||||
* Default default flags
|
||||
*/
|
||||
public static String[] DEFAULT_FLAGS_DEFAULT = new String[] {};
|
||||
|
||||
public boolean USE_ECONOMY = false;
|
||||
public double PLOT_PRICE = 100;
|
||||
public double MERGE_PRICE = 100;
|
||||
}
|
||||
|
@ -91,6 +91,9 @@ public class WorldGenerator extends ChunkGenerator {
|
||||
options.put("worlds." + world + ".flags.default", DEFAULT_FLAGS_DEFAULT);
|
||||
options.put("worlds." + world + ".schematic.schematics", plotworld.SCHEMATICS);
|
||||
options.put("worlds." + world + ".schematic.specify_on_claim", plotworld.SCHEMATIC_CLAIM_SPECIFY);
|
||||
options.put("worlds." + world + ".economy.use", plotworld.USE_ECONOMY);
|
||||
options.put("worlds." + world + ".economy.prices.claim", plotworld.PLOT_PRICE);
|
||||
options.put("worlds." + world + ".economy.prices.merge", plotworld.MERGE_PRICE);
|
||||
for (Entry<String, Object> node : options.entrySet()) {
|
||||
if (!config.contains(node.getKey())) {
|
||||
config.set(node.getKey(), node.getValue());
|
||||
@ -119,6 +122,9 @@ public class WorldGenerator extends ChunkGenerator {
|
||||
this.plotworld.SCHEMATIC_FILE = config.getString("worlds." + world + ".schematic.file");
|
||||
this.plotworld.SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("worlds." + world + ".schematic.specify_on_claim");
|
||||
this.plotworld.SCHEMATICS = config.getStringList("worlds." + world + ".schematic.schematics");
|
||||
this.plotworld.USE_ECONOMY = config.getBoolean("worlds." + world + ".economy.use");
|
||||
this.plotworld.PLOT_PRICE = config.getDouble("worlds." + world + ".economy.prices.claim");
|
||||
this.plotworld.MERGE_PRICE = config.getDouble("worlds." + world + ".economy.prices.merge");
|
||||
|
||||
String[] default_flags_string = config.getStringList("worlds." + world + ".flags.default").toArray(new String[0]);
|
||||
Flag[] default_flags = new Flag[default_flags_string.length];
|
||||
|
@ -9,17 +9,12 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Auto extends SubCommand {
|
||||
|
||||
@ -68,6 +63,32 @@ public class Auto extends SubCommand {
|
||||
id = new PlotId(x, z);
|
||||
if (PlotHelper.getPlot(world, id).owner == null) {
|
||||
Plot plot = PlotHelper.getPlot(world, id);
|
||||
PlotWorld plotworld = PlotMain.getWorldSettings(plot.getWorld());
|
||||
if(PlotMain.useEconomy && plotworld.USE_ECONOMY) {
|
||||
double cost = plotworld.PLOT_PRICE;
|
||||
if(cost > 0d) {
|
||||
Economy economy = PlotMain.economy;
|
||||
if(economy.getBalance(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||
return true;
|
||||
}
|
||||
economy.withdrawPlayer(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
String schematic;
|
||||
if(args.length > 0 && !(schematic = args[0]).equals("")) {
|
||||
if(plotworld.SCHEMATIC_CLAIM_SPECIFY) {
|
||||
if(!plotworld.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
||||
return true;
|
||||
}
|
||||
if(!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean result = Claim.claimPlot(plr, plot, true);
|
||||
br = !result;
|
||||
}
|
||||
|
@ -9,18 +9,12 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
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.PlotHelper;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.PlotWorld;
|
||||
import com.intellectualcrafters.plot.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Citymonstret
|
||||
@ -51,8 +45,20 @@ public class Claim extends SubCommand {
|
||||
PlayerFunctions.sendMessage(plr, C.PLOT_IS_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
|
||||
if(PlotMain.useEconomy && world.USE_ECONOMY) {
|
||||
double cost = world.PLOT_PRICE;
|
||||
if(cost > 0d) {
|
||||
Economy economy = PlotMain.economy;
|
||||
if(economy.getBalance(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||
return true;
|
||||
}
|
||||
economy.withdrawPlayer(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
if(!schematic.equals("")) {
|
||||
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
|
||||
if(world.SCHEMATIC_CLAIM_SPECIFY) {
|
||||
if(!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
||||
|
@ -9,25 +9,15 @@
|
||||
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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.PlotWorld;
|
||||
import com.intellectualcrafters.plot.SetBlockFast;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.events.PlotMergeEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -45,13 +35,34 @@ public class Merge extends SubCommand {
|
||||
|
||||
public static String direction(float yaw) {
|
||||
yaw = yaw / 90;
|
||||
yaw = (float)Math.round(yaw);
|
||||
|
||||
if (yaw == -4 || yaw == 0 || yaw == 4) {return "SOUTH";}
|
||||
if (yaw == -1 || yaw == 3) {return "EAST";}
|
||||
if (yaw == -2 || yaw == 2) {return "NORTH";}
|
||||
if (yaw == -3 || yaw == 1) {return "WEST";}
|
||||
return "";
|
||||
// yaw = (float)Math.round(yaw);
|
||||
/*
|
||||
* if (yaw == -4 || yaw == 0 || yaw == 4) {return "SOUTH";}
|
||||
* if (yaw == -1 || yaw == 3) {return "EAST";}
|
||||
* if (yaw == -2 || yaw == 2) {return "NORTH";}
|
||||
* if (yaw == -3 || yaw == 1) {return "WEST";}
|
||||
*/
|
||||
int i = Math.round(yaw);
|
||||
switch(i) {
|
||||
case -4:
|
||||
case 0:
|
||||
case 4:
|
||||
return "SOUTH";
|
||||
case -1:
|
||||
case 3:
|
||||
return "EAST";
|
||||
case -2:
|
||||
case 2:
|
||||
return "NORTH";
|
||||
case -3:
|
||||
case 1:
|
||||
return "WEST";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Had to... I'm sorry xD But it looks soo much better, and should be equally as fast. //
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -106,7 +117,7 @@ public class Merge extends SubCommand {
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
for (PlotId myid:plots) {
|
||||
for (PlotId myid : plots) {
|
||||
Plot myplot = PlotMain.getPlots(world).get(myid);
|
||||
if (myplot==null || !myplot.hasOwner() || !(myplot.getOwner().equals(plr.getUniqueId()))) {
|
||||
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
||||
@ -117,7 +128,21 @@ public class Merge extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PlotWorld plotWorld = PlotMain.getWorldSettings(world);
|
||||
if(PlotMain.useEconomy && plotWorld.USE_ECONOMY) {
|
||||
double cost = plotWorld.MERGE_PRICE;
|
||||
if(cost > 0d) {
|
||||
Economy economy = PlotMain.economy;
|
||||
if(economy.getBalance(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||
return false;
|
||||
}
|
||||
economy.withdrawPlayer(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
|
||||
PlotMergeEvent event = new PlotMergeEvent(world, plot, plots);
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
|
@ -157,6 +157,7 @@ public class Setup extends SubCommand implements Listener {
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.intellectualcrafters.plot.listeners;
|
||||
|
||||
import com.intellectualcrafters.plot.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -8,20 +9,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.PWE;
|
||||
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.events.PlayerEnterPlotEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user