diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 48c3fc6fd..04768f347 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -6,7 +6,7 @@ com.intellectualcrafters PlotSquared - 2.5.5 + 2.5.6 PlotSquared jar @@ -57,6 +57,11 @@ + + javax.websocket + javax.websocket-api + 1.1 + org.bukkit bukkit diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 9f71e556d..d5ecbb859 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -21,54 +21,6 @@ package com.intellectualcrafters.plot; -import com.google.common.io.Files; -import com.intellectualcrafters.plot.api.PlotAPI; -import com.intellectualcrafters.plot.commands.Auto; -import com.intellectualcrafters.plot.commands.MainCommand; -import com.intellectualcrafters.plot.commands.WE_Anywhere; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.*; -import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; -import com.intellectualcrafters.plot.events.PlotDeleteEvent; -import com.intellectualcrafters.plot.flag.AbstractFlag; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.generator.HybridGen; -import com.intellectualcrafters.plot.generator.HybridPlotManager; -import com.intellectualcrafters.plot.generator.HybridPlotWorld; -import com.intellectualcrafters.plot.listeners.*; -import com.intellectualcrafters.plot.object.*; -import com.intellectualcrafters.plot.util.*; -import com.intellectualcrafters.plot.util.Logger.LogLevel; -import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; -import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; -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.apache.commons.lang.StringUtils; -import org.bukkit.*; -import org.bukkit.command.PluginCommand; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.server.PluginEnableEvent; -import org.bukkit.event.world.WorldLoadEvent; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.InvalidDescriptionException; -import org.bukkit.plugin.InvalidPluginException; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.UnknownDependencyException; -import org.bukkit.plugin.java.JavaPlugin; - import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -76,9 +28,88 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; -import java.util.concurrent.TimeUnit; +import java.util.Set; +import java.util.UUID; + +import me.confuser.barapi.BarAPI; +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.command.PluginCommand; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; + +import com.google.common.io.Files; +import com.intellectualcrafters.plot.commands.MainCommand; +import com.intellectualcrafters.plot.commands.WE_Anywhere; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.config.Settings; +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.events.PlayerTeleportToPlotEvent; +import com.intellectualcrafters.plot.events.PlotDeleteEvent; +import com.intellectualcrafters.plot.flag.AbstractFlag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.generator.HybridGen; +import com.intellectualcrafters.plot.generator.HybridPlotManager; +import com.intellectualcrafters.plot.generator.HybridPlotWorld; +import com.intellectualcrafters.plot.listeners.ForceFieldListener; +import com.intellectualcrafters.plot.listeners.InventoryListener; +import com.intellectualcrafters.plot.listeners.PlayerEvents; +import com.intellectualcrafters.plot.listeners.PlotListener; +import com.intellectualcrafters.plot.listeners.PlotPlusListener; +import com.intellectualcrafters.plot.listeners.WorldEditListener; +import com.intellectualcrafters.plot.listeners.WorldGuardListener; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.ConsoleColors; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.Lag; +import com.intellectualcrafters.plot.util.Logger; +import com.intellectualcrafters.plot.util.Logger.LogLevel; +import com.intellectualcrafters.plot.util.Metrics; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.SendChunk; +import com.intellectualcrafters.plot.util.SetBlockFast; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; +import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; /** * PlotMain class. @@ -1136,6 +1167,29 @@ import java.util.concurrent.TimeUnit; return "Flag value must be a gamemode: 'creative' , 'survival' or 'adventure'"; } }); + + FlagManager.addFlag(new AbstractFlag("price") { + @Override + public String parseValue(final String value) { + try { + double price = Double.parseDouble(value); + if (price >= 0) { + return price + ""; + } + else { + return null; + } + } + catch (Exception e) { + return null; + } + } + + @Override + public String getValueDesc() { + return "Flag value must be a positive number representing the price of the plot'"; + } + }); FlagManager.addFlag(new AbstractFlag("time") { @Override @@ -1288,7 +1342,6 @@ import java.util.concurrent.TimeUnit; Files.copy(file, to); file.delete(); } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); } try { @@ -1309,7 +1362,6 @@ import java.util.concurrent.TimeUnit; * On Load. */ @Override - @SuppressWarnings("deprecation") final public void onEnable() { if (Bukkit.getPluginManager().getPlugin("PlotMe") != null) { CONVERT_PLOTME = true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java new file mode 100644 index 000000000..9232021f8 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -0,0 +1,111 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PlotSquared - A plot manager and world generator for the Bukkit API / +// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / +// / +// This program is free software; you can redistribute it and/or modify / +// it under the terms of the GNU General Public License as published by / +// the Free Software Foundation; either version 3 of the License, or / +// (at your option) any later version. / +// / +// This program is distributed in the hope that it will be useful, / +// but WITHOUT ANY WARRANTY; without even the implied warranty of / +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / +// GNU General Public License for more details. / +// / +// You should have received a copy of the GNU General Public License / +// along with this program; if not, write to the Free Software Foundation, / +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / +// / +// You can contact us via: support@intellectualsites.com / +//////////////////////////////////////////////////////////////////////////////////////////////////// + +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.generator.HybridPlotWorld; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetBlockFast; +import com.intellectualcrafters.plot.util.UUIDHandler; + +import net.milkbowl.vault.economy.Economy; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; + +/** + * @author Citymonstret + */ +public class Buy extends SubCommand { + + public Buy() { + super(Command.BUY, "Buy the plot you are standing on", "b", CommandCategory.CLAIMING, true); + } + + @Override + public boolean execute(final Player plr, final String... args) { + if (!PlotMain.useEconomy) { + return sendMessage(plr, C.ECON_DISABLED); + } + World world = plr.getWorld(); + if (!PlotMain.isPlotWorld(world)) { + return sendMessage(plr, C.NOT_IN_PLOT_WORLD); + } + Plot plot; + if (args.length > 0) { + try { + String[] split = args[0].split(";"); + PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + plot = PlotHelper.getPlot(world, id); + } + catch (Exception e) { + return sendMessage(plr, C.NOT_VALID_PLOT_ID); + } + } + else { + plot = PlayerFunctions.getCurrentPlot(plr); + } + if (plot == null) { + return sendMessage(plr, C.NOT_IN_PLOT); + } + if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions.getAllowedPlots(plr)) { + return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); + } + if (!plot.hasOwner()) { + return sendMessage(plr, C.PLOT_UNOWNED); + } + Flag flag = FlagManager.getPlotFlag(plot, "price"); + if (flag == null) { + return sendMessage(plr, C.NOT_FOR_SALE); + } + double price = Double.parseDouble(flag.getValue()); + PlotId id = plot.id; + PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id; + int size = PlayerFunctions.getPlotSelectionIds(world, id, id2).size(); + PlotWorld plotworld = PlotMain.getWorldSettings(world); + if (plotworld.USE_ECONOMY) { + price += plotworld.PLOT_PRICE * size; + } + if (price > 0d) { + final Economy economy = PlotMain.economy; + if (economy.getBalance(plr) < price) { + return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); + } + economy.withdrawPlayer(plr, price); + sendMessage(plr, C.REMOVED_BALANCE, price + ""); + } + plot.owner = UUIDHandler.getUUID(plr); + DBFunc.setOwner(plot, plot.owner); + PlayerFunctions.sendMessage(plr, C.CLAIMED); + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java index e700b8adc..6660b479a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Command.java @@ -36,6 +36,7 @@ public enum Command { // (Rating system) (ratings can be stored as the average, and number of // ratings) // - /plot rate + BUY("b"), /** * */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 6d4232c6b..e24aeca4f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -82,7 +82,9 @@ public enum C { /* * Economy Stuff */ + ECON_DISABLED("&cEconomy is not enabled"), CANNOT_AFFORD_PLOT("&cYou cannot afford to buy this plot. It costs &6%s"), + NOT_FOR_SALE("&cThis plot is not for sale"), CANNOT_AFFORD_MERGE("&cYou cannot afford to merge the plots. It costs &6%s"), ADDED_BALANCE("&6%s &chas been added to your balance"), REMOVED_BALANCE("&6%s &chas been taken from your balance"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index afaa19662..9870dd54a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -221,8 +221,7 @@ public class HybridGen extends PlotGenerator { } // You can have as many populators as you would like, e.g. tree // populator, ore populator -// return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld)); - return new ArrayList<>(); + return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld)); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java new file mode 100644 index 000000000..6650b123b --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java @@ -0,0 +1,5 @@ +package com.intellectualcrafters.plot.util; + +public class EconHandler { + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index a9c1e6b4b..4981d9982 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -2,21 +2,17 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; - import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.World; +import org.bukkit.entity.Player; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.commands.Auto; -import com.intellectualcrafters.plot.commands.Schematic; -import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.events.PlotDeleteEvent; @@ -129,6 +125,11 @@ public class ExpireManager { if (keep.contains(uuid)) { continue; } + Player player = UUIDHandler.uuidWrapper.getPlayer(uuid); + if (player != null) { + keep.add(uuid); + continue; + } OfflinePlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid); if (!op.hasPlayedBefore()) { toRemove.add(plot);