* Commit WIP flag work.

* More ported flag types, and additions to the flag API.

* Make PlotFlag more generic to allow generic flag creation

* Pull Captions methods into a Caption interface.

* Port MusicFlag

* Port flight flag

* Port UntrustedVisitFlag

* Port DenyExitFlag

* Remove paper suggestion

* Make ListFlag lists immutable

* Update Flag containers. Add javadocs. Add missing methods.

* Port description flag

* Port greeting and farewell flags

* Port weather flag

* Move getExample implementation to BooleanFlag

* Port reserved flags

* Port all boolean flags.

* Remove unused flag types

* Invert liquid-flow flag

* Find the real (legacy) flag name

* Change NOITFY -> NOTIFY in Captions

* Make IntegerFlag extendable

* Port integer flags

* Update Flag command to current API state

* Begin remaking flag command

* Create DoubleFlag + extract common parsing stuff

* Supply arguments in flag parse exceptions

* Implement missing flag subcommands

* Update Flag command to current API state

* Implement PriceFlag

* Port deny-teleport

* Port gamemode flags

* Port BreakFlag

* Port PlaceFlag

* Port UseFlag

* Remove old unused flag constants

* Port blocked-cmds flag

* Fix entity util

* Port TimeFlag

* Use CaptionUtility for formatting

* Port keep flag

* Fix imports

* Reformat code

* Remove unused classes

* Fix MainUtil.java

* Remove FlagCmd

* Add flag info header and footer

* Comment out flag related stuff in SchematicHandler

* Remove FlagManager

* Finalize Plot.java

* Finalize PlotArea.java

* Finalize PlotListener

* Fix API issues

* Fix a bunch of compile errors

* Fix `/plot flag remove`

* Fix initialization of GlobalFlagContainer

* Apply API changes to events

* Update SQLManager to new API

* Invert default value for DenyExitFlag

* Replace flag.getValue().toString() with flag.toString()

* Make FlagContainer instance in Plot final

* Fix various command issues

* Clean up PlotSettings

* Don't show internal flags in flag list

* Fix `/plot flag add`

* Remove the info inventory as it's 100% broken

* Add plot info entries and fix up the default format

* Fix default flag state in Captions

* 781c200 part 2

* Fix odd grammar in captions

* Fix odd grammar in captions v2

* Add create table statements for plot_flags

* Remove old flag references in SQLManager

* Use the new plot_flags table

* Add tab completion to `/plot flag`

* Improve parse error handling

* Make flag permission check recognize parse exceptions

* Initial progress towards flag conversion

* Fix minor issues

* Don't validate flags during flag conversion

* Allow unrecognized flags to be parsed

* Filter out internal flags from command sugguestions

* Use the wrong caption when there's no plot description set

* Limit command suggestions for boolean flags

* Make blocktypelistflags accept blockcategories

* Require categories to be prefixed with '#' and fix some minor display issues

* Fix plot database conversion

* Update PlotFlagEvent.java

Updated return description

* Fix command annotation wrapping

* Add FLAG_UPDATE event for FlagContainer listeners

* Make getParentContainer nullable

* Document castUnsafe in FlagContainer

* Document FlagContainer constructors

* Add missing documentation to FlagContainer

* Document FlagParseException

* Fix wording in FlagContainer javadoc

* Document InternalFlag

* Document PlotFlag

* Minor changes

* Remove revisit comments

Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
Co-authored-by: NotMyFault <mc.cache@web.de>
Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
Alexander Söderberg 2020-02-24 18:42:02 +01:00 committed by GitHub
parent b99631f1bd
commit 9868648fcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
250 changed files with 6229 additions and 3216 deletions

View File

@ -1,6 +1,6 @@
package com.github.intellectualsites.plotsquared.bukkit.events;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList;
/**
* Called when a Flag is added to a plot.
*/
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
public class PlotFlagAddEvent extends PlotFlagEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Flag flag;
private boolean cancelled;
/**
@ -20,24 +19,14 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
* @param flag Flag that was added
* @param plot Plot to which the flag was added
*/
public PlotFlagAddEvent(Flag flag, Plot plot) {
super(plot);
this.flag = flag;
public PlotFlagAddEvent(PlotFlag<?, ?> flag, Plot plot) {
super(plot, flag);
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get the flag involved.
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override public HandlerList getHandlers() {
return handlers;
}

View File

@ -0,0 +1,22 @@
package com.github.intellectualsites.plotsquared.bukkit.events;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
public abstract class PlotFlagEvent extends PlotEvent {
private final PlotFlag<?, ?> flag;
protected PlotFlagEvent(Plot plot, PlotFlag<?, ?> flag) {
super(plot);
this.flag = flag;
}
/**
* Get the flag involved
*
* @return the flag involved
*/
public PlotFlag<?, ?> getFlag() {
return flag;
}
}

View File

@ -1,6 +1,6 @@
package com.github.intellectualsites.plotsquared.bukkit.events;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -8,10 +8,9 @@ import org.bukkit.event.HandlerList;
/**
* Called when a flag is removed from a plot
*/
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
public class PlotFlagRemoveEvent extends PlotFlagEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Flag flag;
private boolean cancelled;
/**
@ -20,24 +19,14 @@ public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
* @param flag Flag that was removed
* @param plot Plot from which the flag was removed
*/
public PlotFlagRemoveEvent(Flag flag, Plot plot) {
super(plot);
this.flag = flag;
public PlotFlagRemoveEvent(PlotFlag<?, ?> flag, Plot plot) {
super(plot, flag);
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
@Override public HandlerList getHandlers() {
return handlers;
}

View File

@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
@ -118,7 +118,7 @@ public class EntitySpawnListener implements Listener {
}
return;
}
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
event.setCancelled(true);
}
switch (entity.getType()) {

View File

@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ForcefieldFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -80,7 +80,7 @@ import java.util.UUID;
}
public static void handleForcefield(Player player, PlotPlayer plotPlayer, Plot plot) {
if (Flags.FORCEFIELD.isTrue(plot)) {
if (plot.getFlag(ForcefieldFlag.class)) {
UUID uuid = plotPlayer.getUUID();
if (plot.isAdded(uuid)) {
Set<PlotPlayer> players = getNearbyPlayers(player, plot);

View File

@ -7,10 +7,63 @@ import com.github.intellectualsites.plotsquared.bukkit.util.UpdateUtility;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalAttackFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalCapFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockedCmdsFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.BreakFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.EntityCapFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.GrassGrowFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingBreakFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HangingPlaceFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileAttackFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileCapFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HostileInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceFormFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.IceMeltFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.KelpGrowFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.LiquidFlowFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscBreakFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscCapFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobCapFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobPlaceFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MycelGrowFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlaceFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlayerInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PveFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PvpFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.RedstoneFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.SnowFormFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.SnowMeltFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.SoilDryFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedAttackFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleBreakFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleCapFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleUseFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.VillagerInteractFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.VineGrowFlag;
import com.github.intellectualsites.plotsquared.plot.flags.types.BlockTypeWrapper;
import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType;
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotHandler;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.StringWrapper;
import com.github.intellectualsites.plotsquared.plot.util.EntityUtil;
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@ -135,7 +188,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
@ -185,7 +237,7 @@ import java.util.regex.Pattern;
public static boolean checkEntity(Entity entity, Plot plot) {
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot
.getArea().DEFAULT_FLAGS.isEmpty()) {
.getArea().getFlagContainer().getFlagMap().isEmpty()) {
return false;
}
switch (entity.getType()) {
@ -220,11 +272,13 @@ import java.util.regex.Pattern;
case UNKNOWN:
case WITHER_SKULL:
// non moving / unmovable
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP);
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
case ARMOR_STAND:
case ITEM_FRAME:
case PAINTING:
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
MiscCapFlag.MISC_CAP_UNLIMITED);
// misc
case BOAT:
case MINECART:
@ -234,7 +288,9 @@ import java.util.regex.Pattern;
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case MINECART_TNT:
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
case BAT:
case CHICKEN:
case CAT:
@ -267,8 +323,10 @@ import java.util.regex.Pattern;
case WOLF:
case ZOMBIE_HORSE:
// animal
return EntityUtil
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED,
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
case BLAZE:
case CAVE_SPIDER:
case CREEPER:
@ -303,26 +361,39 @@ import java.util.regex.Pattern;
case RAVAGER:
// monster
return EntityUtil
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED,
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
default:
if (entity instanceof LivingEntity) {
if (entity instanceof Animals || entity instanceof WaterMob) {
return EntityUtil
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.ANIMAL_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED,
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
} else if (entity instanceof Monster) {
return EntityUtil
.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP, Flags.HOSTILE_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED,
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
} else {
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MOB_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
MobCapFlag.MOB_CAP_UNLIMITED);
}
}
if (entity instanceof Vehicle) {
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.VEHICLE_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
}
if (entity instanceof Hanging) {
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP, Flags.MISC_CAP);
return EntityUtil.checkEntity(plot,
EntityCapFlag.ENTITY_CAP_UNLIMITED,
MiscCapFlag.MISC_CAP_UNLIMITED);
}
return EntityUtil.checkEntity(plot, Flags.ENTITY_CAP);
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
}
}
@ -409,7 +480,7 @@ import java.util.regex.Pattern;
if (plot == null) {
return;
}
if (Flags.REDSTONE.isFalse(plot)) {
if (!plot.getFlag(RedstoneFlag.class)) {
event.setNewCurrent(0);
return;
}
@ -463,7 +534,7 @@ import java.util.regex.Pattern;
if (plot == null) {
return;
}
if (Flags.REDSTONE.isFalse(plot)) {
if (!plot.getFlag(RedstoneFlag.class)) {
event.setCancelled(true);
}
return;
@ -485,7 +556,7 @@ import java.util.regex.Pattern;
if (plot == null) {
return;
}
if (Flags.DISABLE_PHYSICS.isFalse(plot)) {
if (plot.getFlag(DisablePhysicsFlag.class)) {
event.setCancelled(true);
}
return;
@ -631,10 +702,10 @@ import java.util.regex.Pattern;
if (plot == null) {
return;
}
Optional<List<String>> flag = plot.getFlag(Flags.BLOCKED_CMDS);
if (flag.isPresent() && !Permissions
List<String> blockedCommands = plot.getFlag(BlockedCmdsFlag.class);
if (!blockedCommands.isEmpty() && !Permissions
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) {
List<String> blockedCommands = flag.get();
String part = parts[0];
if (parts[0].contains(":")) {
part = parts[0].split(":")[1];
@ -771,12 +842,12 @@ import java.util.regex.Pattern;
}
Plot plot = area.getPlot(location);
if (plot != null) {
final boolean result = Flags.DENY_TELEPORT.allowsTeleport(pp, plot);
final boolean result = DenyTeleportFlag.allowsTeleport(pp, plot);
// there is one possibility to still allow teleportation:
// to is identical to the plot's home location, and untrusted-visit is true
// i.e. untrusted-visit can override deny-teleport
// this is acceptable, because otherwise it wouldn't make sense to have both flags set
if (!result && !(Flags.UNTRUSTED_VISIT.isTrue(plot) && plot.getHome().equals(BukkitUtil.getLocationFull(to)))) {
if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot.getHome().equals(BukkitUtil.getLocationFull(to)))) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_ENTRY_DENIED);
event.setCancelled(true);
@ -1078,12 +1149,14 @@ import java.util.regex.Pattern;
return;
}
if (!plot.isAdded(plotPlayer.getUUID())) {
Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
List<BlockTypeWrapper> destroy = plot.getFlag(BreakFlag.class);
Block block = event.getBlock();
if (destroy.isPresent() && destroy.get()
.contains(BukkitAdapter.asBlockType(block.getType()))) {
final BlockType blockType = BukkitAdapter.asBlockType(block.getType());
for (final BlockTypeWrapper blockTypeWrapper : destroy) {
if (blockTypeWrapper.accepts(blockType)) {
return;
}
}
if (Permissions
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
return;
@ -1091,7 +1164,7 @@ import java.util.regex.Pattern;
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
} else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER);
@ -1129,7 +1202,7 @@ import java.util.regex.Pattern;
}
Plot plot = area.getOwnedPlot(location);
if (plot != null) {
if (Flags.EXPLOSION.isTrue(plot)) {
if (plot.getFlag(ExplosionFlag.class)) {
List<MetadataValue> meta = event.getEntity().getMetadata("plot");
Plot origin;
if (meta.isEmpty()) {
@ -1204,7 +1277,7 @@ import java.util.regex.Pattern;
PlotArea area = location.getPlotArea();
if (area != null) {
Plot plot = area.getOwnedPlot(location);
if (plot != null && Flags.MOB_BREAK.isTrue(plot)) {
if (plot != null && plot.getFlag(MobPlaceFlag.class)) {
return;
}
event.setCancelled(true);
@ -1233,7 +1306,7 @@ import java.util.regex.Pattern;
Player player = (Player) entity;
if (!plot.hasOwner()) {
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (Flags.ICE_FORM.isTrue(plot)) {
if (plot.getFlag(IceFormFlag.class)) {
return;
}
event.setCancelled(true);
@ -1241,7 +1314,7 @@ import java.util.regex.Pattern;
}
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (!plot.isAdded(plotPlayer.getUUID())) {
if (Flags.ICE_FORM.isTrue(plot)) {
if (plot.getFlag(IceFormFlag.class)) {
return;
}
event.setCancelled(true);
@ -1249,7 +1322,7 @@ import java.util.regex.Pattern;
}
return;
}
if (!Flags.ICE_FORM.isTrue(plot)) {
if (!plot.getFlag(IceFormFlag.class)) {
event.setCancelled(true);
}
}
@ -1272,22 +1345,22 @@ import java.util.regex.Pattern;
}
switch (event.getSource().getType()) {
case GRASS:
if (Flags.GRASS_GROW.isFalse(plot)) {
if (!plot.getFlag(GrassGrowFlag.class)) {
event.setCancelled(true);
}
break;
case MYCELIUM:
if (Flags.MYCEL_GROW.isFalse(plot)) {
if (!plot.getFlag(MycelGrowFlag.class)) {
event.setCancelled(true);
}
break;
case VINE:
if (Flags.VINE_GROW.isFalse(plot)) {
if (!plot.getFlag(VineGrowFlag.class)) {
event.setCancelled(true);
}
break;
case KELP:
if (Flags.KELP_GROW.isFalse(plot)) {
if (!plot.getFlag(KelpGrowFlag.class)) {
event.setCancelled(true);
}
break;
@ -1313,14 +1386,14 @@ import java.util.regex.Pattern;
switch (event.getNewState().getType()) {
case SNOW:
case SNOW_BLOCK:
if (Flags.SNOW_FORM.isFalse(plot)) {
if (!plot.getFlag(SnowFormFlag.class)) {
event.setCancelled(true);
}
return;
case ICE:
case FROSTED_ICE:
case PACKED_ICE:
if (Flags.ICE_FORM.isFalse(plot)) {
if (!plot.getFlag(IceFormFlag.class)) {
event.setCancelled(true);
}
}
@ -1351,10 +1424,9 @@ import java.util.regex.Pattern;
}
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (!plot.isAdded(plotPlayer.getUUID())) {
Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
List<BlockTypeWrapper> destroy = plot.getFlag(BreakFlag.class);
Block block = event.getBlock();
if (destroy.isPresent() && destroy.get()
.contains(BukkitAdapter.asBlockType(block.getType())) || Permissions
if (destroy.contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType()))) || Permissions
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
return;
}
@ -1385,17 +1457,17 @@ import java.util.regex.Pattern;
}
switch (block.getType()) {
case ICE:
if (Flags.ICE_MELT.isFalse(plot)) {
if (!plot.getFlag(IceMeltFlag.class)) {
event.setCancelled(true);
}
break;
case SNOW:
if (Flags.SNOW_MELT.isFalse(plot)) {
if (!plot.getFlag(SnowMeltFlag.class)) {
event.setCancelled(true);
}
break;
case FARMLAND:
if (Flags.SOIL_DRY.isFalse(plot)) {
if (!plot.getFlag(SoilDryFlag.class)) {
event.setCancelled(true);
}
break;
@ -1414,7 +1486,7 @@ import java.util.regex.Pattern;
Plot plot = area.getOwnedPlot(tLocation);
Location fLocation = BukkitUtil.getLocation(from.getLocation());
if (plot != null) {
if (Flags.DISABLE_PHYSICS.isFalse(plot)) {
if (plot.getFlag(DisablePhysicsFlag.class)) {
event.setCancelled(true);
return;
} else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
@ -1422,7 +1494,7 @@ import java.util.regex.Pattern;
event.setCancelled(true);
return;
}
if (Flags.LIQUID_FLOW.isFalse(plot)) {
if (!plot.getFlag(LiquidFlowFlag.class)) {
switch (to.getType()) {
case WATER:
case LAVA:
@ -1816,7 +1888,7 @@ import java.util.regex.Pattern;
e.setCancelled(true);
}
} else {
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER);
e.setCancelled(true);
@ -1834,7 +1906,7 @@ import java.util.regex.Pattern;
if (plot.isAdded(uuid)) {
return;
}
if (Flags.MISC_INTERACT.isTrue(plot)) {
if (plot.getFlag(MiscInteractFlag.class)) {
return;
}
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
@ -1866,7 +1938,7 @@ import java.util.regex.Pattern;
return;
}
Plot plot = area.getOwnedPlot(location);
if (plot == null || !plot.getFlag(Flags.EXPLOSION).orElse(false)) {
if (plot == null || !plot.getFlag(ExplosionFlag.class)) {
event.setCancelled(true);
}
event.blockList().removeIf(
@ -2119,7 +2191,7 @@ import java.util.regex.Pattern;
return;
}
Plot plot = area.getOwnedPlotAbs(location);
if (plot == null || plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
event.setCancelled(true);
return;
}
@ -2155,7 +2227,7 @@ import java.util.regex.Pattern;
}
Plot plot = location.getOwnedPlot();
if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) {
if (plot == null || !plot.getFlag(BlockBurnFlag.class)) {
event.setCancelled(true);
}
@ -2198,7 +2270,7 @@ import java.util.regex.Pattern;
Captions.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true);
}
} else if (Flags.BLOCK_IGNITION.isFalse(plot)) {
} else if (!plot.getFlag(BlockIgnitionFlag.class)) {
event.setCancelled(true);
}
} else {
@ -2207,7 +2279,7 @@ import java.util.regex.Pattern;
return;
}
if (ignitingEntity != null) {
if (!plot.getFlag(Flags.BLOCK_IGNITION, false)) {
if (!plot.getFlag(BlockIgnitionFlag.class)) {
event.setCancelled(true);
return;
}
@ -2233,11 +2305,11 @@ import java.util.regex.Pattern;
Block ignitingBlock = event.getIgnitingBlock();
Plot plotIgnited = BukkitUtil.getLocation(ignitingBlock.getLocation()).getPlot();
if (igniteCause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL && (
!plot.getFlag(Flags.BLOCK_IGNITION, false) || plotIgnited == null
!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null
|| !plotIgnited.equals(plot)) ||
(igniteCause == BlockIgniteEvent.IgniteCause.SPREAD
|| igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && (
!plot.getFlag(Flags.BLOCK_IGNITION).orElse(false) || plotIgnited == null
!plot.getFlag(BlockIgnitionFlag.class) || plotIgnited == null
|| !plotIgnited.equals(plot))) {
event.setCancelled(true);
}
@ -2273,16 +2345,20 @@ import java.util.regex.Pattern;
Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
event.setCancelled(true);
} else if (!plot.isAdded(pp.getUUID())) {
if (Flags.USE.contains(plot, BukkitAdapter.asItemType(block.getType()))) {
List<BlockTypeWrapper> use = plot.getFlag(UseFlag.class);
final BlockType blockType = BukkitAdapter.asBlockType(block.getType());
for (final BlockTypeWrapper blockTypeWrapper : use) {
if (blockTypeWrapper.accepts(blockType)) {
return;
}
}
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
return;
}
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true);
} else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER);
@ -2333,18 +2409,21 @@ import java.util.regex.Pattern;
Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
event.setCancelled(true);
} else if (!plot.isAdded(plotPlayer.getUUID())) {
Optional<Set<BlockType>> use = plot.getFlag(Flags.USE);
List<BlockTypeWrapper> use = plot.getFlag(UseFlag.class);
Block block = event.getBlockClicked();
if (use.isPresent() && use.get().contains(BukkitAdapter.asBlockType(block.getType()))) {
final BlockType blockType = BukkitAdapter.asBlockType(block.getType());
for (final BlockTypeWrapper blockTypeWrapper : use) {
if (blockTypeWrapper.accepts(blockType)) {
return;
}
}
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
return;
}
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true);
} else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER);
@ -2404,7 +2483,7 @@ import java.util.regex.Pattern;
return;
}
if (!plot.isAdded(pp.getUUID())) {
if (!plot.getFlag(Flags.HANGING_PLACE, false)) {
if (!plot.getFlag(HangingPlaceFlag.class)) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER);
@ -2445,7 +2524,7 @@ import java.util.regex.Pattern;
event.setCancelled(true);
}
} else if (!plot.isAdded(pp.getUUID())) {
if (plot.getFlag(Flags.HANGING_BREAK, false)) {
if (plot.getFlag(HangingBreakFlag.class)) {
return;
}
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
@ -2474,7 +2553,7 @@ import java.util.regex.Pattern;
event.setCancelled(true);
}
} else if (!plot.isAdded(player.getUUID())) {
if (!plot.getFlag(Flags.HANGING_BREAK, false)) {
if (!plot.getFlag(HangingBreakFlag.class)) {
if (!Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT,
@ -2514,26 +2593,26 @@ import java.util.regex.Pattern;
}
} else if (!plot.isAdded(pp.getUUID())) {
Entity entity = event.getRightClicked();
if (entity instanceof Monster && plot.getFlag(Flags.HOSTILE_INTERACT, false)) {
if (entity instanceof Monster && plot.getFlag(HostileInteractFlag.class)) {
return;
}
if (entity instanceof Animals && plot.getFlag(Flags.ANIMAL_INTERACT, false)) {
if (entity instanceof Animals && plot.getFlag(AnimalInteractFlag.class)) {
return;
}
if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot
.getFlag(Flags.TAMED_INTERACT, false)) {
if (entity instanceof Tameable && ((Tameable) entity).isTamed() && plot.getFlag(
TamedInteractFlag.class)) {
return;
}
if (entity instanceof Vehicle && plot.getFlag(Flags.VEHICLE_USE, false)) {
if (entity instanceof Vehicle && plot.getFlag(VehicleUseFlag.class)) {
return;
}
if (entity instanceof Player && plot.getFlag(Flags.PLAYER_INTERACT, false)) {
if (entity instanceof Player && plot.getFlag(PlayerInteractFlag.class)) {
return;
}
if (entity instanceof Villager && plot.getFlag(Flags.VILLAGER_INTERACT, false)) {
if (entity instanceof Villager && plot.getFlag(VillagerInteractFlag.class)) {
return;
}
if (entity instanceof ItemFrame && plot.getFlag(Flags.MISC_INTERACT, false)) {
if (entity instanceof ItemFrame && plot.getFlag(MiscInteractFlag.class)) {
return;
}
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_OTHER)) {
@ -2573,7 +2652,7 @@ import java.util.regex.Pattern;
return;
}
if (!plot.isAdded(pp.getUUID())) {
if (plot.getFlag(Flags.VEHICLE_BREAK, false)) {
if (plot.getFlag(VehicleBreakFlag.class)) {
return;
}
if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.other")) {
@ -2739,9 +2818,9 @@ import java.util.regex.Pattern;
if (player != null) {
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (victim instanceof Hanging) { // hanging
if (plot != null && (plot.getFlag(Flags.HANGING_BREAK, false) || plot
.isAdded(plotPlayer.getUUID()))) {
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
if (plot != null && (plot.getFlag(HangingBreakFlag.class)) || plot
.isAdded(plotPlayer.getUUID())) {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER);
return false;
@ -2755,7 +2834,7 @@ import java.util.regex.Pattern;
return false;
}
} else if (victim.getType() == EntityType.ARMOR_STAND) {
if (plot != null && (plot.getFlag(Flags.MISC_BREAK, false) || plot
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
.isAdded(plotPlayer.getUUID()))) {
return true;
}
@ -2766,8 +2845,8 @@ import java.util.regex.Pattern;
}
} else if (victim instanceof Monster
|| victim instanceof EnderDragon) { // victim is monster
if (plot != null && (plot.getFlag(Flags.HOSTILE_ATTACK, false) || plot
.getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
if (plot != null && (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) ||
plot.isAdded(plotPlayer.getUUID()))) {
return true;
}
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
@ -2776,8 +2855,8 @@ import java.util.regex.Pattern;
return false;
}
} else if (victim instanceof Tameable) { // victim is tameable
if (plot != null && (plot.getFlag(Flags.TAMED_ATTACK, false) || plot
.getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
if (plot != null && (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) ||
plot.isAdded(plotPlayer.getUUID()))) {
return true;
}
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
@ -2787,7 +2866,7 @@ import java.util.regex.Pattern;
}
} else if (victim instanceof Player) {
if (plot != null) {
if (Flags.PVP.isFalse(plot) && !Permissions
if (!plot.getFlag(PvpFlag.class) && !Permissions
.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
"plots.admin.pvp." + stub);
@ -2802,8 +2881,8 @@ import java.util.regex.Pattern;
return false;
}
} else if (victim instanceof Creature) { // victim is animal
if (plot != null && (plot.getFlag(Flags.ANIMAL_ATTACK, false) || plot
.getFlag(Flags.PVE, false) || plot.isAdded(plotPlayer.getUUID()))) {
if (plot != null && (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class)
|| plot.isAdded(plotPlayer.getUUID()))) {
return true;
}
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
@ -2814,7 +2893,7 @@ import java.util.regex.Pattern;
} else if (victim instanceof Vehicle) { // Vehicles are managed in vehicle destroy event
return true;
} else { // victim is something else
if (plot != null && (plot.getFlag(Flags.PVE, false) || plot
if (plot != null && (plot.getFlag(PveFlag.class) || plot
.isAdded(plotPlayer.getUUID()))) {
return true;
}
@ -2827,7 +2906,7 @@ import java.util.regex.Pattern;
return true;
} else if (dplot != null && (!dplot.equals(vplot) || Objects
.equals(dplot.guessOwner(), vplot.guessOwner()))) {
return vplot != null && Flags.PVE.isTrue(vplot);
return vplot != null && vplot.getFlag(PveFlag.class);
}
//disable the firework damage. too much of a headache to support at the moment.
if (vplot != null) {
@ -2836,7 +2915,7 @@ import java.util.regex.Pattern;
return false;
}
}
return ((vplot != null && Flags.PVE.isTrue(vplot)) || !(damager instanceof Arrow
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
&& !(victim instanceof Creature)));
}
@ -2896,10 +2975,10 @@ import java.util.regex.Pattern;
return;
}
} else if (!plot.isAdded(pp.getUUID())) {
Set<BlockType> place = plot.getFlag(Flags.PLACE, null);
List<BlockTypeWrapper> place = plot.getFlag(PlaceFlag.class);
if (place != null) {
Block block = event.getBlock();
if (place.contains(BukkitAdapter.asBlockType(block.getType()))) {
if (place.contains(BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) {
return;
}
}
@ -2909,7 +2988,7 @@ import java.util.regex.Pattern;
event.setCancelled(true);
return;
}
} else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
} else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER);
@ -2917,7 +2996,7 @@ import java.util.regex.Pattern;
return;
}
}
if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
if (plot.getFlag(DisablePhysicsFlag.class)) {
Block block = event.getBlockPlaced();
if (block.getType().hasGravity()) {
sendBlockChange(block.getLocation(), block.getBlockData());

View File

@ -3,8 +3,13 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEvent;
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerLeavePlotEvent;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flag.IntervalFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DropProtectionFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.FeedFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HealFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.InstabreakFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.InvincibleFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ItemDropFlag;
import com.github.intellectualsites.plotsquared.plot.flags.types.TimedFlag;
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -28,7 +33,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
@ -90,7 +94,7 @@ import java.util.UUID;
if (plot == null) {
return;
}
if (Flags.INSTABREAK.isTrue(plot)) {
if (plot.getFlag(InstabreakFlag.class)) {
Block block = event.getBlock();
BlockBreakEvent call = new BlockBreakEvent(block, player);
Bukkit.getServer().getPluginManager().callEvent(call);
@ -108,7 +112,7 @@ import java.util.UUID;
if (plot == null) {
return;
}
if (Flags.INVINCIBLE.isTrue(plot)) {
if (plot.getFlag(InvincibleFlag.class)) {
event.setCancelled(true);
}
}
@ -122,7 +126,7 @@ import java.util.UUID;
}
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
if (Flags.ITEM_DROP.isFalse(plot)) {
if (!plot.getFlag(ItemDropFlag.class)) {
event.setCancelled(true);
}
}
@ -131,12 +135,14 @@ import java.util.UUID;
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
Player player = event.getPlayer();
Plot plot = event.getPlot();
Optional<IntervalFlag.Interval> feed = plot.getFlag(Flags.FEED);
feed.ifPresent(value -> feedRunnable
.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
Optional<IntervalFlag.Interval> heal = plot.getFlag(Flags.HEAL);
heal.ifPresent(value -> healRunnable
.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
TimedFlag.Timed<Integer> feed = plot.getFlag(FeedFlag.class);
if (feed.getInterval() != 0 && feed.getValue() != 0) {
feedRunnable.put(player.getUniqueId(), new Interval(feed.getInterval(), feed.getValue(), 20));
}
TimedFlag.Timed<Integer> heal = plot.getFlag(HealFlag.class);
if (heal.getInterval() != 0 && heal.getValue() != 0) {
healRunnable.put(player.getUniqueId(), new Interval(heal.getInterval(), heal.getValue(), 20));
}
}
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
@ -166,7 +172,7 @@ import java.util.UUID;
return;
}
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) {
if (!plot.isAdded(uuid) && plot.getFlag(DropProtectionFlag.class)) {
event.setCancelled(true);
}
}

View File

@ -18,7 +18,7 @@ import com.github.intellectualsites.plotsquared.bukkit.events.PlotMergeEvent;
import com.github.intellectualsites.plotsquared.bukkit.events.PlotRateEvent;
import com.github.intellectualsites.plotsquared.bukkit.events.PlotUnlinkEvent;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
@ -75,11 +75,11 @@ public final class BukkitEventUtil extends EventUtil {
return callEvent(new PlotDeleteEvent(plot));
}
@Override public boolean callFlagAdd(Flag flag, Plot plot) {
@Override public boolean callFlagAdd(PlotFlag<?, ?> flag, Plot plot) {
return callEvent(new PlotFlagAddEvent(flag, plot));
}
@Override public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
@Override public boolean callFlagRemove(PlotFlag<?, ?> flag, Plot plot, Object value) {
return callEvent(new PlotFlagRemoveEvent(flag, plot));
}

View File

@ -15,6 +15,7 @@ dependencies {
annotationProcessor("org.projectlombok:lombok:1.18.8")
testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.61")
implementation("org.jetbrains:annotations:18.0.0")
}
sourceCompatibility = 1.8

View File

@ -2,9 +2,8 @@ package com.github.intellectualsites.plotsquared.api;
import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Caption;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -164,19 +163,10 @@ import java.util.UUID;
* @see #sendConsoleMessage(String)
* @see Captions
*/
public void sendConsoleMessage(Captions caption) {
public void sendConsoleMessage(Caption caption) {
sendConsoleMessage(caption.getTranslated());
}
/**
* Registers a flag for use in plots.
*
* @param flag the flag to register
*/
public void addFlag(Flag<?> flag) {
Flags.registerFlag(flag);
}
/**
* Gets the PlotSquared class.
*

View File

@ -81,7 +81,8 @@ public abstract class Command {
&& types[2] == String[].class && types[3] == RunnableVal3.class
&& types[4] == RunnableVal2.class) {
Command tmp = new Command(this, true) {
@Override public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
try {
@ -264,8 +265,7 @@ public abstract class Command {
if (totalPages != 0) { // Back
new PlotMessage().text("<-").color("$1").command(baseCommand + " " + page).text(" | ")
.color("$3").text("->").color("$3").text(Captions.CLICKABLE.getTranslated())
.color("$2")
.send(player);
.color("$2").send(player);
}
}

View File

@ -186,7 +186,7 @@ public class JSONObject {
* @param object An object that has fields that should be used to make a JSONObject.
* @param names An array of strings, the names of the fields to be obtained from the object.
*/
public JSONObject(Object object, String names[]) {
public JSONObject(Object object, String[] names) {
this();
Class c = object.getClass();
for (String name : names) {

View File

@ -5,6 +5,8 @@ import com.github.intellectualsites.plotsquared.configuration.MemorySection;
import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerialization;
import com.github.intellectualsites.plotsquared.plot.commands.WE_Anywhere;
import com.github.intellectualsites.plotsquared.plot.config.Caption;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
@ -193,6 +195,17 @@ import java.util.zip.ZipInputStream;
if (Settings.Enabled_Components.DATABASE) {
setupDatabase();
}
// Check if we need to convert old flag values, etc
if (!getConfigurationVersion().equalsIgnoreCase("v5")) {
// Perform upgrade
if (DBFunc.dbManager.convertFlags()) {
log(Captions.PREFIX.getTranslated() + "Flags were converted successfully!");
// Update the config version
setConfigurationVersion("v5");
}
}
// Comments
CommentManager.registerDefaultInboxes();
// Kill entities
@ -243,7 +256,8 @@ import java.util.zip.ZipInputStream;
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
try {
if (this.IMP.initWorldEdit()) {
PlotSquared.log(Captions.PREFIX + "&6" + IMP.getPluginName() + " hooked into WorldEdit.");
PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + IMP.getPluginName()
+ " hooked into WorldEdit.");
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WESubscriber());
if (Settings.Enabled_Components.COMMANDS) {
@ -316,7 +330,7 @@ import java.util.zip.ZipInputStream;
e.printStackTrace();
}
PlotSquared.log(Captions.PREFIX + Captions
PlotSquared.log(Captions.PREFIX + CaptionUtility
.format(ConsolePlayer.getConsole(), Captions.ENABLED.getTranslated(), IMP.getPluginName()));
}
@ -343,7 +357,9 @@ import java.util.zip.ZipInputStream;
* @see IPlotMain#log(String)
*/
public static void log(Object message) {
if (message == null || message.toString().isEmpty()) {
if (message == null || (message instanceof Caption ?
((Caption) message).getTranslated().isEmpty() :
message.toString().isEmpty())) {
return;
}
if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) {
@ -1644,9 +1660,9 @@ import java.util.zip.ZipInputStream;
this.worlds = YamlConfiguration.loadConfiguration(this.worldsFile);
if (this.worlds.contains("worlds")) {
if (!this.worlds.contains("configuration_version") || !this.worlds
.getString("configuration_version")
.equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION)) {
if (!this.worlds.contains("configuration_version") ||
(!this.worlds.getString("configuration_version").equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) &&
!this.worlds.getString("configuration_version").equalsIgnoreCase("v5"))) {
// Conversion needed
log(Captions.LEGACY_CONFIG_FOUND.getTranslated());
try {
@ -1657,10 +1673,8 @@ import java.util.zip.ZipInputStream;
this.worlds.getConfigurationSection("worlds");
final LegacyConverter converter = new LegacyConverter(worlds);
converter.convert();
this.worlds
.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION);
this.worlds.set("worlds", worlds); // Redundant, but hey... ¯\_()_/¯
this.worlds.save(this.worldsFile);
this.worlds.set("worlds", worlds);
this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION);
log(Captions.LEGACY_CONFIG_DONE.getTranslated());
} catch (final Exception e) {
log(Captions.LEGACY_CONFIG_CONVERSION_FAILED.getTranslated());
@ -1736,6 +1750,15 @@ import java.util.zip.ZipInputStream;
return true;
}
public String getConfigurationVersion() {
return this.worlds.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION).toString();
}
public void setConfigurationVersion(final String newVersion) throws IOException {
this.worlds.set("configuration_version", newVersion);
this.worlds.save(this.worldsFile);
}
/**
* Setup the storage file (load + save missing nodes).
*/
@ -1766,7 +1789,8 @@ import java.util.zip.ZipInputStream;
if (this.version != null) {
this.style.set("Version", this.version.toString());
}
this.style.set("Information", "Left Row: PlotSquared color codes ($), right row: Minecraft color codes (&)");
this.style.set("Information",
"Left Row: PlotSquared color codes ($), right row: Minecraft color codes (&)");
Map<String, Object> object = new HashMap<>(16);
object.put("color.1", "6");
object.put("color.2", "7");

View File

@ -19,8 +19,11 @@ import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "add",
description = "Allow a user to build in a plot while the plot owner is online.",
usage = "/plot add <player|*>", category = CommandCategory.SETTINGS, permission = "plots.add",
requiredType = RequiredType.PLAYER) public class Add extends Command {
usage = "/plot add <player|*>",
category = CommandCategory.SETTINGS,
permission = "plots.add",
requiredType = RequiredType.PLAYER)
public class Add extends Command {
public Add() {
super(MainCommand.getInstance(), true);

View File

@ -12,11 +12,14 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
@CommandDeclaration(command = "setalias", permission = "plots.alias",
description = "Set the plot name", usage = "/plot alias <set|remove> <alias>",
@CommandDeclaration(command = "setalias",
permission = "plots.alias",
description = "Set the plot name",
usage = "/plot alias <set|remove> <alias>",
aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER) public class Alias
extends SubCommand {
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class Alias extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {

View File

@ -33,11 +33,15 @@ import java.util.ArrayList;
import java.util.Objects;
import java.util.Set;
@CommandDeclaration(command = "area", permission = "plots.area",
category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE,
description = "Create a new PlotArea", aliases = "world",
usage = "/plot area <create|info|list|tp|regen>", confirmation = true) public class Area
extends SubCommand {
@CommandDeclaration(command = "area",
permission = "plots.area",
category = CommandCategory.ADMINISTRATION,
requiredType = RequiredType.NONE,
description = "Create a new PlotArea",
aliases = "world",
usage = "/plot area <create|info|list|tp|regen>",
confirmation = true)
public class Area extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length == 0) {
@ -135,14 +139,14 @@ import java.util.Set;
if (WorldUtil.IMP.isWorld(world)) {
PlotSquared.get().loadWorld(world, null);
Captions.SETUP_FINISHED.send(player);
player.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND);
player.teleport(WorldUtil.IMP.getSpawn(world),
TeleportCause.COMMAND);
if (area.TERRAIN != 3) {
ChunkManager.largeRegionTask(world, region,
new RunnableVal<BlockVector2>() {
@Override public void run(BlockVector2 value) {
AugmentedUtils
.generate(world, value.getX(), value.getZ(),
null);
AugmentedUtils.generate(world, value.getX(),
value.getZ(), null);
}
}, null);
}
@ -258,7 +262,8 @@ import java.util.Set;
String world = SetupUtils.manager.setupWorld(object);
if (WorldUtil.IMP.isWorld(world)) {
Captions.SETUP_FINISHED.send(player);
player.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND);
player.teleport(WorldUtil.IMP.getSpawn(world),
TeleportCause.COMMAND);
} else {
MainUtil.sendMessage(player,
"An error occurred while creating the world: "
@ -285,13 +290,15 @@ import java.util.Set;
}
if (WorldUtil.IMP.isWorld(pa.worldname)) {
if (!player.getLocation().getWorld().equals(pa.worldname)) {
player.teleport(WorldUtil.IMP.getSpawn(pa.worldname), TeleportCause.COMMAND);
player.teleport(WorldUtil.IMP.getSpawn(pa.worldname),
TeleportCause.COMMAND);
}
} else {
object.terrain = 0;
object.type = 0;
SetupUtils.manager.setupWorld(object);
player.teleport(WorldUtil.IMP.getSpawn(pa.worldname), TeleportCause.COMMAND);
player.teleport(WorldUtil.IMP.getSpawn(pa.worldname),
TeleportCause.COMMAND);
}
player.setMeta("area_create_area", pa);
MainUtil.sendMessage(player,
@ -432,10 +439,11 @@ import java.util.Set;
"$4Stop the server and delete: " + area.worldname + "/region");
return false;
}
ChunkManager
.largeRegionTask(area.worldname, area.getRegion(), new RunnableVal<BlockVector2>() {
ChunkManager.largeRegionTask(area.worldname, area.getRegion(),
new RunnableVal<BlockVector2>() {
@Override public void run(BlockVector2 value) {
AugmentedUtils.generate(area.worldname, value.getX(), value.getZ(), null);
AugmentedUtils
.generate(area.worldname, value.getX(), value.getZ(), null);
}
}, () -> player.sendMessage("Regen complete"));
return true;
@ -463,9 +471,10 @@ import java.util.Set;
center = WorldUtil.IMP.getSpawn(area.worldname);
} else {
CuboidRegion region = area.getRegion();
center =
new Location(area.worldname, region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2,
0, region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2);
center = new Location(area.worldname, region.getMinimumPoint().getX()
+ (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2,
0, region.getMinimumPoint().getZ()
+ (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2);
center.setY(1 + WorldUtil.IMP
.getHighestBlock(area.worldname, center.getX(), center.getZ()));
}

View File

@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
@ -22,9 +23,13 @@ import org.jetbrains.annotations.Nullable;
import java.util.Set;
@CommandDeclaration(command = "auto", permission = "plots.auto",
category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE,
description = "Claim the nearest plot", aliases = "a", usage = "/plot auto [length,width]")
@CommandDeclaration(command = "auto",
permission = "plots.auto",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
description = "Claim the nearest plot",
aliases = "a",
usage = "/plot auto [length,width]")
public class Auto extends SubCommand {
@Deprecated public static PlotId getNextPlotId(PlotId id, int step) {
@ -219,12 +224,13 @@ public class Auto extends SubCommand {
sendMessage(player, Captions.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!Permissions.hasPermission(player,
Captions.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic))
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic))
&& !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic));
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(),
schematic));
return true;
}
}

View File

@ -9,16 +9,21 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
@CommandDeclaration(command = "setbiome", permission = "plots.set.biome",
description = "Set the plot biome", usage = "/plot biome [biome]",
aliases = {"biome", "sb", "setb", "b"}, category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE) public class Biome extends SetCommand {
@CommandDeclaration(command = "setbiome",
permission = "plots.set.biome",
description = "Set the plot biome",
usage = "/plot biome [biome]",
aliases = {"biome", "sb", "setb", "b"},
category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE)
public class Biome extends SetCommand {
@Override public boolean set(final PlotPlayer player, final Plot plot, final String value) {
BiomeType biome = null;
try {
biome = BiomeTypes.get(value.toLowerCase());
} catch (final Exception ignore) {}
} catch (final Exception ignore) {
}
if (biome == null) {
String biomes = StringMan
.join(BiomeType.REGISTRY.values(), Captions.BLOCK_LIST_SEPARATOR.getTranslated());

View File

@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
@ -12,13 +12,16 @@ import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "buy", description = "Buy the plot you are standing on",
usage = "/plot buy", permission = "plots.buy", category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE) public class Buy extends Command {
@CommandDeclaration(command = "buy",
description = "Buy the plot you are standing on",
usage = "/plot buy",
permission = "plots.buy",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE)
public class Buy extends Command {
public Buy() {
super(MainCommand.getInstance(), true);
@ -41,11 +44,10 @@ import java.util.concurrent.CompletableFuture;
Set<Plot> plots = plot.getConnectedPlots();
checkTrue(player.getPlotCount() + plots.size() <= player.getAllowedPlots(),
Captions.CANT_CLAIM_MORE_PLOTS);
Optional<Double> flag = plot.getFlag(Flags.PRICE);
if (!flag.isPresent()) {
double price = plot.getFlag(PriceFlag.class);
if (price <= 0) {
throw new CommandException(Captions.NOT_FOR_SALE);
}
final double price = flag.get();
checkTrue(player.getMoney() >= price, Captions.CANNOT_AFFORD_PLOT);
player.withdraw(price);
// Failure
@ -58,7 +60,7 @@ import java.util.concurrent.CompletableFuture;
if (owner != null) {
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
}
plot.removeFlag(Flags.PRICE);
plot.removeFlag(PriceFlag.class);
plot.setOwner(player.getUUID());
Captions.CLAIMED.send(player);
whenDone.run(Buy.this, CommandResult.SUCCESS);

View File

@ -3,9 +3,13 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@CommandDeclaration(command = "chat", description = "Toggle plot chat on or off",
usage = "/plot chat [on|off]", permission = "plots.chat", category = CommandCategory.CHAT,
requiredType = RequiredType.PLAYER) public class Chat extends SubCommand {
@CommandDeclaration(command = "chat",
description = "Toggle plot chat on or off",
usage = "/plot chat [on|off]",
permission = "plots.chat",
category = CommandCategory.CHAT,
requiredType = RequiredType.PLAYER)
public class Chat extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
MainCommand.getInstance().toggle.chat(this, player, new String[0], null, null);

View File

@ -1,6 +1,7 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
@ -16,9 +17,13 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.google.common.primitives.Ints;
@CommandDeclaration(command = "claim", aliases = "c",
description = "Claim the current plot you're standing on", category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER, permission = "plots.claim", usage = "/plot claim")
@CommandDeclaration(command = "claim",
aliases = "c",
description = "Claim the current plot you're standing on",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER,
permission = "plots.claim",
usage = "/plot claim")
public class Claim extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@ -37,8 +42,7 @@ public class Claim extends SubCommand {
int grants = 0;
if (currentPlots >= player.getAllowedPlots()) {
if (player.hasPersistentMeta("grantedPlots")) {
grants =
Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
grants = Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
if (grants <= 0) {
player.removePersistentMeta("grantedPlots");
return sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
@ -57,8 +61,7 @@ public class Claim extends SubCommand {
return sendMessage(player, Captions.SCHEMATIC_INVALID,
"non-existent: " + schematic);
}
if (!Permissions
.hasPermission(player, Captions
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic))
&& !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) {
@ -85,8 +88,7 @@ public class Claim extends SubCommand {
if (grants == 1) {
player.removePersistentMeta("grantedPlots");
} else {
player.setPersistentMeta("grantedPlots",
Ints.toByteArray(grants - 1));
player.setPersistentMeta("grantedPlots", Ints.toByteArray(grants - 1));
}
sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1));
}

View File

@ -4,8 +4,8 @@ import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnalysisFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
@ -16,9 +16,15 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "clear", description = "Clear the plot you stand on", requiredType = RequiredType.NONE,
permission = "plots.clear", category = CommandCategory.APPEARANCE, usage = "/plot clear",
aliases = "reset", confirmation = true) public class Clear extends Command {
@CommandDeclaration(command = "clear",
description = "Clear the plot you stand on",
requiredType = RequiredType.NONE,
permission = "plots.clear",
category = CommandCategory.APPEARANCE,
usage = "/plot clear",
aliases = "reset",
confirmation = true)
public class Clear extends Command {
// Note: To clear a specific plot use /plot <plot> clear
// The syntax also works with any command: /plot <plot> <command>
@ -36,7 +42,7 @@ import java.util.concurrent.CompletableFuture;
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_CLEAR),
Captions.NO_PLOT_PERMS);
checkTrue(plot.getRunning() == 0, Captions.WAIT_FOR_TIMER);
checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions
checkTrue(!Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot) || Permissions
.hasPermission(player, Captions.PERMISSION_CONTINUE), Captions.DONE_ALREADY_DONE);
confirm.run(this, () -> {
final long start = System.currentTimeMillis();
@ -45,11 +51,11 @@ import java.util.concurrent.CompletableFuture;
GlobalBlockQueue.IMP.addEmptyTask(() -> {
plot.removeRunning();
// If the state changes, then mark it as no longer done
if (plot.getFlag(Flags.DONE).isPresent()) {
FlagManager.removePlotFlag(plot, Flags.DONE);
if (DoneFlag.isDone(plot)) {
plot.removeFlag(DoneFlag.class);
}
if (plot.getFlag(Flags.ANALYSIS).isPresent()) {
FlagManager.removePlotFlag(plot, Flags.ANALYSIS);
if (!plot.getFlag(AnalysisFlag.class).isEmpty()) {
plot.removeFlag(AnalysisFlag.class);
}
MainUtil.sendMessage(player, Captions.CLEARING_DONE,
"" + (System.currentTimeMillis() - start));

View File

@ -22,10 +22,13 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@CommandDeclaration(command = "cluster", aliases = "clusters",
category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.NONE,
permission = "plots.cluster", description = "Manage a plot cluster") public class Cluster
extends SubCommand {
@CommandDeclaration(command = "cluster",
aliases = "clusters",
category = CommandCategory.ADMINISTRATION,
requiredType = RequiredType.NONE,
permission = "plots.cluster",
description = "Manage a plot cluster")
public class Cluster extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {

View File

@ -6,7 +6,8 @@ import lombok.RequiredArgsConstructor;
/**
* CommandCategory.
*/
@RequiredArgsConstructor public enum CommandCategory {
@RequiredArgsConstructor
public enum CommandCategory {
/**
* Claiming CommandConfig.
* Such as: /plot claim

View File

@ -16,8 +16,12 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import java.util.Arrays;
import java.util.Map.Entry;
@CommandDeclaration(command = "comment", aliases = {"msg"}, description = "Comment on a plot",
category = CommandCategory.CHAT, requiredType = RequiredType.PLAYER, permission = "plots.comment")
@CommandDeclaration(command = "comment",
aliases = {"msg"},
description = "Comment on a plot",
category = CommandCategory.CHAT,
requiredType = RequiredType.PLAYER,
permission = "plots.comment")
public class Comment extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {

View File

@ -19,10 +19,13 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
@CommandDeclaration(command = "condense", permission = "plots.admin",
@CommandDeclaration(command = "condense",
permission = "plots.admin",
usage = "/plot condense <area> <start|stop|info> [radius]",
description = "Condense a plotworld", category = CommandCategory.ADMINISTRATION,
requiredType = RequiredType.CONSOLE) public class Condense extends SubCommand {
description = "Condense a plotworld",
category = CommandCategory.ADMINISTRATION,
requiredType = RequiredType.CONSOLE)
public class Condense extends SubCommand {
public static boolean TASK = false;

View File

@ -9,9 +9,11 @@ import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
@CommandDeclaration(command = "confirm", permission = "plots.use",
description = "Confirm an action", category = CommandCategory.INFO) public class Confirm
extends SubCommand {
@CommandDeclaration(command = "confirm",
permission = "plots.use",
description = "Confirm an action",
category = CommandCategory.INFO)
public class Confirm extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
CmdInstance command = CmdConfirm.getPending(player);

View File

@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@ -11,8 +11,10 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
@CommandDeclaration(command = "continue",
description = "Continue a plot that was previously marked as done",
permission = "plots.continue", category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER) public class Continue extends SubCommand {
permission = "plots.continue",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class Continue extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
Plot plot = player.getCurrentPlot();
@ -24,7 +26,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
if (!plot.hasFlag(Flags.DONE)) {
if (!DoneFlag.isDone(plot)) {
MainUtil.sendMessage(player, Captions.DONE_NOT_DONE);
return false;
}
@ -39,7 +41,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER);
return false;
}
plot.removeFlag(Flags.DONE);
plot.removeFlag(DoneFlag.class);
MainUtil.sendMessage(player, Captions.DONE_REMOVED);
return true;
}

View File

@ -8,9 +8,14 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
@CommandDeclaration(command = "copy", permission = "plots.copy", aliases = {"copypaste"},
category = CommandCategory.CLAIMING, description = "Copy a plot", usage = "/plot copy <X;Z>",
requiredType = RequiredType.NONE) public class Copy extends SubCommand {
@CommandDeclaration(command = "copy",
permission = "plots.copy",
aliases = {"copypaste"},
category = CommandCategory.CLAIMING,
description = "Copy a plot",
usage = "/plot copy <X;Z>",
requiredType = RequiredType.NONE)
public class Copy extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
Location location = player.getLocation();

View File

@ -9,11 +9,14 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@CommandDeclaration(command = "createroadschematic", aliases = {"crs"},
category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.PLAYER,
@CommandDeclaration(command = "createroadschematic",
aliases = {"crs"},
category = CommandCategory.ADMINISTRATION,
requiredType = RequiredType.PLAYER,
permission = "plots.createroadschematic",
description = "Add a road schematic to your world using the roads around your current plot",
usage = "/plot createroadschematic") public class CreateRoadSchematic extends SubCommand {
usage = "/plot createroadschematic")
public class CreateRoadSchematic extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
Location location = player.getLocation();

View File

@ -22,11 +22,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
@CommandDeclaration(command = "database", aliases = {"convert"},
category = CommandCategory.ADMINISTRATION, permission = "plots.database",
description = "Convert/Backup Storage", requiredType = RequiredType.CONSOLE,
usage = "/plot database [area] <sqlite|mysql|import>") public class Database
extends SubCommand {
@CommandDeclaration(command = "database",
aliases = {"convert"},
category = CommandCategory.ADMINISTRATION,
permission = "plots.database",
description = "Convert/Backup Storage",
requiredType = RequiredType.CONSOLE,
usage = "/plot database [area] <sqlite|mysql|import>")
public class DatabaseCommand extends SubCommand {
public static void insertPlots(final SQLManager manager, final List<Plot> plots,
final PlotPlayer player) {
@ -159,7 +162,7 @@ import java.util.Map.Entry;
}
try {
SQLManager manager = new SQLManager(implementation, prefix, true);
Database.insertPlots(manager, plots, player);
DatabaseCommand.insertPlots(manager, plots, player);
return true;
} catch (ClassNotFoundException | SQLException e) {
MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info");

View File

@ -9,8 +9,11 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import java.util.Map;
@CommandDeclaration(command = "debug", category = CommandCategory.DEBUG,
description = "Show debug information", usage = "/plot debug [msg]", permission = "plots.admin")
@CommandDeclaration(command = "debug",
category = CommandCategory.DEBUG,
description = "Show debug information",
usage = "/plot debug [msg]",
permission = "plots.admin")
public class Debug extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {

View File

@ -9,9 +9,12 @@ import java.util.List;
import java.util.UUID;
@CommandDeclaration(command = "debugallowunsafe",
description = "Allow unsafe actions until toggled off", usage = "/plot debugallowunsafe",
category = CommandCategory.DEBUG, requiredType = RequiredType.NONE,
permission = "plots.debugallowunsafe") public class DebugAllowUnsafe extends SubCommand {
description = "Allow unsafe actions until toggled off",
usage = "/plot debugallowunsafe",
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.debugallowunsafe")
public class DebugAllowUnsafe extends SubCommand {
public static final List<UUID> unsafeAllowed = new ArrayList<>();

View File

@ -22,9 +22,13 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugclaimtest", description =
@CommandDeclaration(command = "debugclaimtest",
description =
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. "
+ "Execution time may vary", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE, permission = "plots.debugclaimtest")
+ "Execution time may vary",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.debugclaimtest")
public class DebugClaimTest extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@ -56,7 +60,8 @@ public class DebugClaimTest extends SubCommand {
PlotManager manager = area.getPlotManager();
CompletableFuture.runAsync(() -> {
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(min, max);
MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: " + ids.size() + " plot ids to check!");
MainUtil.sendMessage(player,
"&3Sign Block&8->&3Plot&8: " + ids.size() + " plot ids to check!");
for (PlotId id : ids) {
Plot plot = area.getPlotAbs(id);
if (plot.hasOwner()) {
@ -74,7 +79,8 @@ public class DebugClaimTest extends SubCommand {
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = map.get(new StringWrapper(line));
if (uuid == null) {
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map.entrySet()) {
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map
.entrySet()) {
if (stringWrapperUUIDEntry.getKey().value.toLowerCase()
.startsWith(line.toLowerCase())) {
uuid = stringWrapperUUIDEntry.getValue();
@ -86,11 +92,13 @@ public class DebugClaimTest extends SubCommand {
uuid = UUIDHandler.getUUID(line, null);
}
if (uuid != null) {
MainUtil.sendMessage(player, " - &aFound plot: " + plot.getId() + " : " + line);
MainUtil.sendMessage(player,
" - &aFound plot: " + plot.getId() + " : " + line);
plot.setOwner(uuid);
MainUtil.sendMessage(player, " - &8Updated plot: " + plot.getId());
} else {
MainUtil.sendMessage(player, " - &cInvalid PlayerName: " + plot.getId() + " : " + line);
MainUtil.sendMessage(player,
" - &cInvalid PlayerName: " + plot.getId() + " : " + line);
}
}
}

View File

@ -6,8 +6,8 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
import com.github.intellectualsites.plotsquared.plot.listener.WEManager;
import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer;
@ -55,9 +55,12 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugexec", permission = "plots.admin",
description = "Mutli-purpose debug command", aliases = {"exec", "$"},
category = CommandCategory.DEBUG) public class DebugExec extends SubCommand {
@CommandDeclaration(command = "debugexec",
permission = "plots.admin",
description = "Mutli-purpose debug command",
aliases = {"exec", "$"},
category = CommandCategory.DEBUG)
public class DebugExec extends SubCommand {
private ScriptEngine engine;
private Bindings scope;
@ -120,7 +123,6 @@ import java.util.concurrent.CompletableFuture;
this.scope.put("Settings", new Settings());
this.scope.put("StringMan", new StringMan());
this.scope.put("MathMan", new MathMan());
this.scope.put("FlagManager", new FlagManager());
// Classes
this.scope.put("Location", Location.class);
@ -220,10 +222,11 @@ import java.util.concurrent.CompletableFuture;
return false;
}
String flag = args[1];
final PlotFlag<?, ?> flagInstance =
GlobalFlagContainer.getInstance().getFlagFromString(flag);
if (flagInstance != null) {
for (Plot plot : PlotSquared.get().getBasePlots()) {
Flag<?> flag1 = FlagManager.getFlag(flag);
if (plot.getFlag(flag1).isPresent()) {
plot.removeFlag(flag1);
plot.removeFlag(flagInstance);
}
}
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
@ -306,8 +309,8 @@ import java.util.concurrent.CompletableFuture;
System.getProperty("line.separator"));
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null,
RequiredType.NONE, CommandCategory.DEBUG) {
@Override public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
@Override public CompletableFuture<Boolean> execute(PlotPlayer player,
String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
try {
DebugExec.this.scope.put("PlotPlayer", player);

View File

@ -1,52 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.Argument;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
@CommandDeclaration(command = "debugfixflags", usage = "/plot debugfixflags <world>",
permission = "plots.debugfixflags", description = "Attempt to fix all flags for a world",
requiredType = RequiredType.CONSOLE, category = CommandCategory.DEBUG)
public class DebugFixFlags extends SubCommand {
public DebugFixFlags() {
super(Argument.String);
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]);
if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD, args[0]);
return false;
}
MainUtil.sendMessage(player, "&8--- &6Starting task &8 ---");
for (Plot plot : area.getPlots()) {
HashMap<Flag<?>, Object> flags = plot.getFlags();
Iterator<Entry<Flag<?>, Object>> i = flags.entrySet().iterator();
boolean changed = false;
while (i.hasNext()) {
if (i.next().getKey() == null) {
changed = true;
i.remove();
}
}
if (changed) {
DBFunc.setFlags(plot, plot.getFlags());
}
}
MainUtil.sendMessage(player, "&aDone!");
return true;
}
}

View File

@ -18,9 +18,12 @@ import java.io.File;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugimportworlds", permission = "plots.admin",
description = "Import worlds by player name", requiredType = RequiredType.CONSOLE,
category = CommandCategory.TELEPORT) public class DebugImportWorlds extends Command {
@CommandDeclaration(command = "debugimportworlds",
permission = "plots.admin",
description = "Import worlds by player name",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.TELEPORT)
public class DebugImportWorlds extends Command {
public DebugImportWorlds() {
super(MainCommand.getInstance(), true);
}

View File

@ -5,10 +5,13 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@CommandDeclaration(command = "debugloadtest", permission = "plots.debugloadtest",
@CommandDeclaration(command = "debugloadtest",
permission = "plots.debugloadtest",
description = "This debug command will force the reload of all plots in the DB",
usage = "/plot debugloadtest", category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE) public class DebugLoadTest extends SubCommand {
usage = "/plot debugloadtest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE)
public class DebugLoadTest extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
PlotSquared.get().plots_tmp = DBFunc.getPlots();

View File

@ -28,9 +28,14 @@ import java.util.stream.Collectors;
import static com.github.intellectualsites.plotsquared.plot.util.PremiumVerification.getDownloadID;
import static com.github.intellectualsites.plotsquared.plot.util.PremiumVerification.getUserID;
@CommandDeclaration(command = "debugpaste", aliases = "dp", usage = "/plot debugpaste",
@CommandDeclaration(command = "debugpaste",
aliases = "dp",
usage = "/plot debugpaste",
description = "Upload settings.yml, worlds.yml, PlotSquared.use_THIS.yml your latest.log and Multiverse's worlds.yml (if being used) to https://athion.net/ISPaster/paste",
permission = "plots.debugpaste", category = CommandCategory.DEBUG, confirmation = true, requiredType = RequiredType.NONE)
permission = "plots.debugpaste",
category = CommandCategory.DEBUG,
confirmation = true,
requiredType = RequiredType.NONE)
public class DebugPaste extends SubCommand {
private static String readFile(@NonNull final File file) throws IOException {
@ -54,14 +59,16 @@ public class DebugPaste extends SubCommand {
"# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your "
+ "problem\n\n");
b.append("# PlotSquared Information\n");
b.append("This PlotSquared version is licensed to the spigot user ").append(getUserID()).append(" under ").append(getDownloadID()).append("\n");
b.append("This PlotSquared version is licensed to the spigot user ")
.append(getUserID()).append(" under ").append(getDownloadID()).append("\n");
b.append("# Server Information\n");
b.append("Server Version: ").append(PlotSquared.get().IMP.getServerImplementation())
.append("\n");
b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';')
.append(!Settings.UUID.OFFLINE).append('\n');
b.append("Plugins:");
for (Map.Entry<Map.Entry<String, String>, Boolean> pluginInfo : PlotSquared.get().IMP.getPluginIds()) {
for (Map.Entry<Map.Entry<String, String>, Boolean> pluginInfo : PlotSquared
.get().IMP.getPluginIds()) {
Map.Entry<String, String> nameVersion = pluginInfo.getKey();
String name = nameVersion.getKey();
String version = nameVersion.getValue();
@ -72,12 +79,17 @@ public class DebugPaste extends SubCommand {
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
Runtime runtime = Runtime.getRuntime();
RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
b.append("Uptime: ").append(TimeUnit.MINUTES.convert(rb.getUptime(), TimeUnit.MILLISECONDS) + " minutes").append('\n');
b.append("Uptime: ").append(
TimeUnit.MINUTES.convert(rb.getUptime(), TimeUnit.MILLISECONDS) + " minutes")
.append('\n');
b.append("JVM Flags: ").append(rb.getInputArguments()).append('\n');
b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024 + " MB").append('\n');
b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024 + " MB").append('\n');
b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024 + " MB")
.append('\n');
b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024 + " MB")
.append('\n');
b.append("Java Name: ").append(rb.getVmName()).append('\n');
b.append("Java Version: '").append(System.getProperty("java.version")).append("'\n");
b.append("Java Version: '").append(System.getProperty("java.version"))
.append("'\n");
b.append("Java Vendor: '").append(System.getProperty("java.vendor")).append("'\n");
b.append("Operating System: '").append(System.getProperty("os.name")).append("'\n");
b.append("OS Version: ").append(System.getProperty("os.version")).append('\n');
@ -124,12 +136,13 @@ public class DebugPaste extends SubCommand {
}
try {
final File MultiverseWorlds =
new File(PlotSquared.get().IMP.getDirectory(), "../Multiverse-Core/worlds.yml");
incendoPaster
.addFile(new IncendoPaster.PasteFile("MultiverseCore/worlds.yml", readFile(MultiverseWorlds)));
final File MultiverseWorlds = new File(PlotSquared.get().IMP.getDirectory(),
"../Multiverse-Core/worlds.yml");
incendoPaster.addFile(new IncendoPaster.PasteFile("MultiverseCore/worlds.yml",
readFile(MultiverseWorlds)));
} catch (final IOException ignored) {
MainUtil.sendMessage(player, "&cSkipping Multiverse worlds.yml because the plugin is not in use");
MainUtil.sendMessage(player,
"&cSkipping Multiverse worlds.yml because the plugin is not in use");
}
try {

View File

@ -13,10 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import java.util.Arrays;
@CommandDeclaration(command = "debugroadregen", usage = DebugRoadRegen.USAGE,
@CommandDeclaration(command = "debugroadregen",
usage = DebugRoadRegen.USAGE,
requiredType = RequiredType.NONE,
description = "Regenerate roads in the plot or region the user is, based on the road schematic",
category = CommandCategory.DEBUG, permission = "plots.debugroadregen")
category = CommandCategory.DEBUG,
permission = "plots.debugroadregen")
public class DebugRoadRegen extends SubCommand {
public static final String USAGE = "/plot debugroadregen <plot|region [height]>";
@ -67,13 +69,11 @@ public class DebugRoadRegen extends SubCommand {
height = Integer.parseInt(args[0]);
} catch (NumberFormatException ignored) {
MainUtil.sendMessage(player, Captions.NOT_VALID_NUMBER, "(0, 256)");
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
DebugRoadRegen.USAGE);
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE);
return false;
}
} else if (args.length != 0) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
DebugRoadRegen.USAGE);
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE);
return false;
}

View File

@ -9,8 +9,10 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import java.util.ArrayList;
@CommandDeclaration(command = "debugsavetest", permission = "plots.debugsavetest",
category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE,
@CommandDeclaration(command = "debugsavetest",
permission = "plots.debugsavetest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
usage = "/plot debugsavetest",
description = "This command will force the recreation of all plots in the DB")
public class DebugSaveTest extends SubCommand {

View File

@ -15,10 +15,15 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
@CommandDeclaration(command = "delete", permission = "plots.delete",
description = "Delete the plot you stand on", usage = "/plot delete",
aliases = {"dispose", "del", "unclaim"}, category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE, confirmation = true) public class Delete extends SubCommand {
@CommandDeclaration(command = "delete",
permission = "plots.delete",
description = "Delete the plot you stand on",
usage = "/plot delete",
aliases = {"dispose", "del", "unclaim"},
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
confirmation = true)
public class Delete extends SubCommand {
// Note: To delete a specific plot use /plot <plot> delete
// The syntax also works with any command: /plot <plot> <command>

View File

@ -18,10 +18,13 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
import java.util.Set;
import java.util.UUID;
@CommandDeclaration(command = "deny", aliases = {"d", "ban"},
description = "Deny a user from entering a plot", usage = "/plot deny <player|*>",
category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER) public class Deny
extends SubCommand {
@CommandDeclaration(command = "deny",
aliases = {"d", "ban"},
description = "Deny a user from entering a plot",
usage = "/plot deny <player|*>",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class Deny extends SubCommand {
public Deny() {
super(Argument.PlayerName);

View File

@ -2,24 +2,30 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@CommandDeclaration(command = "setdescription", permission = "plots.set.desc",
description = "Set the plot description", usage = "/plot desc <description>",
aliases = {"desc", "setdesc", "setd", "description"}, category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER) public class Desc extends SetCommand {
@CommandDeclaration(command = "setdescription",
permission = "plots.set.desc",
description = "Set the plot description",
usage = "/plot desc <description>",
aliases = {"desc", "setdesc", "setd", "description"},
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class Desc extends SetCommand {
@Override public boolean set(PlotPlayer player, Plot plot, String desc) {
if (desc.isEmpty()) {
plot.removeFlag(Flags.DESCRIPTION);
plot.removeFlag(DescriptionFlag.class);
MainUtil.sendMessage(player, Captions.DESC_UNSET);
return true;
}
boolean result = FlagManager.addPlotFlag(plot, Flags.DESCRIPTION, desc);
boolean result = plot.setFlag(
GlobalFlagContainer.getInstance().getFlag(DescriptionFlag.class)
.createFlagInstance(desc));
if (!result) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED);
return false;

View File

@ -3,10 +3,13 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@CommandDeclaration(command = "dislike", permission = "plots.dislike",
description = "Dislike the plot", usage = "/plot dislike [next|purge]",
category = CommandCategory.INFO, requiredType = RequiredType.PLAYER) public class Dislike
extends SubCommand {
@CommandDeclaration(command = "dislike",
permission = "plots.dislike",
description = "Dislike the plot",
usage = "/plot dislike [next|purge]",
category = CommandCategory.INFO,
requiredType = RequiredType.PLAYER)
public class Dislike extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
return Like.handleLike(player, args, false);

View File

@ -3,7 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
@ -14,9 +14,13 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
@CommandDeclaration(command = "done", aliases = {"submit"}, description = "Mark a plot as done",
permission = "plots.done", category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE) public class Done extends SubCommand {
@CommandDeclaration(command = "done",
aliases = {"submit"},
description = "Mark a plot as done",
permission = "plots.done",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE)
public class Done extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
Location location = player.getLocation();
@ -29,7 +33,7 @@ import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
if (plot.hasFlag(Flags.DONE)) {
if (DoneFlag.isDone(plot)) {
MainUtil.sendMessage(player, Captions.DONE_ALREADY_DONE);
return false;
}
@ -59,7 +63,7 @@ import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
private void finish(Plot plot, PlotPlayer pp, boolean success) {
if (success) {
long flagValue = System.currentTimeMillis() / 1000;
plot.setFlag(Flags.DONE, flagValue);
plot.setFlag(DoneFlag.class, Long.toString(flagValue));
MainUtil.sendMessage(pp, Captions.DONE_SUCCESS);
} else {
MainUtil.sendMessage(pp, Captions.DONE_INSUFFICIENT_COMPLEXITY);

View File

@ -4,7 +4,7 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
@ -17,10 +17,14 @@ import com.sk89q.jnbt.CompoundTag;
import java.net.URL;
@CommandDeclaration(usage = "/plot download [schematic|world]", command = "download",
aliases = {"dl"}, category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE,
description = "Download your plot", permission = "plots.download") public class Download
extends SubCommand {
@CommandDeclaration(usage = "/plot download [schematic|world]",
command = "download",
aliases = {"dl"},
category = CommandCategory.SCHEMATIC,
requiredType = RequiredType.NONE,
description = "Download your plot",
permission = "plots.download")
public class Download extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
String world = player.getLocation().getWorld();
@ -35,8 +39,8 @@ import java.net.URL;
MainUtil.sendMessage(player, Captions.PLOT_UNOWNED);
return false;
}
if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!plot.getFlag(Flags.DONE).isPresent()))
&& !Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) {
if ((Settings.Done.REQUIRED_FOR_DOWNLOAD && (!DoneFlag.isDone(plot))) && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DOWNLOAD)) {
MainUtil.sendMessage(player, Captions.DONE_NOT_DONE);
return false;
}

View File

@ -1,343 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.BlockStateListFlag;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flag.IntegerFlag;
import com.github.intellectualsites.plotsquared.plot.flag.ListFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.PlotWeather;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.sk89q.worldedit.world.block.BlockType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@CommandDeclaration(command = "setflag", aliases = {"f", "flag",
"setflag"}, usage = "/plot flag <set|remove|add|list|info> <flag> <value>", description = "Set plot flags", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag")
public class FlagCmd extends SubCommand {
private boolean checkPermValue(PlotPlayer player, Flag flag, String key, String value) {
key = key.toLowerCase();
value = value.toLowerCase();
String perm = Captions
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(),
value.toLowerCase());
if (flag instanceof IntegerFlag && MathMan.isInteger(value)) {
try {
int numeric = Integer.parseInt(value);
perm = perm.substring(0, perm.length() - value.length() - 1);
if (numeric > 0) {
int checkRange = PlotSquared.get().getPlatform().equalsIgnoreCase("bukkit") ?
numeric :
Settings.Limit.MAX_PLOTS;
final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric;
if (!result) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), value.toLowerCase()));
}
return result;
}
} catch (NumberFormatException ignore) {
}
} else if (flag instanceof BlockStateListFlag) {
final BlockStateListFlag blockListFlag = (BlockStateListFlag) flag;
Set<BlockType> parsedBlocks = blockListFlag.parseValue(value);
for (final BlockType block : parsedBlocks) {
final String permission = Captions
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), block.toString().toLowerCase());
final boolean result = Permissions.hasPermission(player, permission);
if (!result) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), value.toLowerCase()));
return false;
}
}
return true;
}
final boolean result = Permissions.hasPermission(player, perm);
if (!result) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(), key.toLowerCase(),
value.toLowerCase()));
}
return result;
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
/*
* plot flag set fly true
* plot flag remove fly
* plot flag remove use 1,3
* plot flag add use 2,4
* plot flag list
*/
if (args.length == 0) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, getUsage());
return false;
}
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
MainUtil.sendMessage(player, Captions.NOT_IN_PLOT);
return false;
}
if (!plot.hasOwner()) {
sendMessage(player, Captions.PLOT_NOT_CLAIMED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions
.hasPermission(player, Captions.PERMISSION_SET_FLAG_OTHER)) {
MainUtil
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_SET_FLAG_OTHER);
return false;
}
Flag<?> flag = null;
if (args.length > 1) {
flag = FlagManager.getFlag(args[1]);
if (flag == null || flag.isReserved()) {
boolean suggested = false;
try {
StringComparison<Flag<?>> stringComparison =
new StringComparison<>(args[1], Flags.getFlags());
String best = stringComparison.getBestMatch();
if (best != null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG_SUGGESTED, best);
suggested = true;
}
} catch (final Exception ignored) { /* Happens sometimes because of mean code */ }
if (!suggested) {
MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG);
}
return false;
}
}
switch (args[0].toLowerCase()) {
case "info": {
if (!Permissions.hasPermission(player, Captions.PERMISSION_SET_FLAG)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, "plots.flag.info");
return false;
}
if (args.length != 2) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag info <flag>");
return false;
}
// flag key
MainUtil.sendMessage(player, Captions.FLAG_KEY, flag.getName());
// flag type
MainUtil.sendMessage(player, Captions.FLAG_TYPE, flag.getClass().getSimpleName());
// Flag type description
MainUtil.sendMessage(player, Captions.FLAG_DESC, flag.getValueDescription());
return true;
}
case "set": {
if (!Permissions.hasPermission(player, Captions.PERMISSION_SET_FLAG)) {
MainUtil
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_SET_FLAG);
return false;
}
if (args.length < 3) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
"/plot flag set <flag> <value>");
return false;
}
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
if (!checkPermValue(player, flag, args[1], value)) {
return false;
}
Object parsed = flag.parseValue(value);
if (parsed == null) {
MainUtil.sendMessage(player, "&c" + flag.getValueDescription());
return false;
}
if (flag instanceof ListFlag) {
if (!(parsed instanceof Collection) || ((Collection) parsed).isEmpty()) {
return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED);
}
}
boolean result = plot.setFlag(flag, parsed);
if (!result) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(player, Captions.FLAG_ADDED);
return true;
}
case "remove": {
if (!Permissions.hasPermission(player, Captions.PERMISSION_FLAG_REMOVE)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_FLAG_REMOVE);
return false;
}
if (args.length != 2 && args.length != 3) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
"/plot flag remove <flag> [values]");
return false;
}
if (!Permissions.hasPermission(player, Captions
.format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(),
args[1].toLowerCase()))) {
if (args.length != 3) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions
.format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(),
args[1].toLowerCase()));
return false;
}
for (String entry : args[2].split(",")) {
if (!checkPermValue(player, flag, args[1], entry)) {
return false;
}
}
}
if (args.length == 3 && flag instanceof ListFlag) {
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final ListFlag<? extends Collection> listFlag = (ListFlag<? extends Collection>) flag;
final Optional<? extends Collection> collectionOptional = plot.getFlag(listFlag);
if (collectionOptional.isPresent()) {
final Collection parsedCollection = (Collection) flag.parseValue(value);
if (parsedCollection.isEmpty()) {
return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
}
final Collection flagCollection = collectionOptional.get();
if (flagCollection.removeAll(parsedCollection)) {
if (flagCollection.isEmpty()) {
if (plot.removeFlag(flag)) {
return MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
} else {
return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
}
} else {
MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
}
} else {
return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
}
}
DBFunc.setFlags(plot, plot.getFlags());
return true;
} else {
boolean result = plot.removeFlag(flag);
if (!result) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return false;
}
}
if (flag == Flags.TIME) {
player.setTime(Long.MAX_VALUE);
} else if (flag == Flags.WEATHER) {
player.setWeather(PlotWeather.RESET);
}
MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
return true;
}
case "add":
if (!Permissions.hasPermission(player, Captions.PERMISSION_FLAG_ADD)) {
MainUtil
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_FLAG_ADD);
return false;
}
if (args.length < 3) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
"/plot flag add <flag> <values>");
return false;
}
for (String entry : args[2].split(",")) {
if (!checkPermValue(player, flag, args[1], entry)) {
return false;
}
}
String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
Object parsed = flag.parseValue(value);
if (parsed == null) {
MainUtil.sendMessage(player, "&c" + flag.getValueDescription());
return false;
}
Object val = parsed;
if (flag instanceof ListFlag) {
final Collection parsedCollection = (Collection<?>) parsed;
if (parsedCollection.isEmpty()) {
return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED);
}
final ListFlag<? extends Collection> listFlag = (ListFlag<? extends Collection>) flag;
final Optional<? extends Collection> collectionOptional = plot.getFlag(listFlag);
if (collectionOptional.isPresent()) {
final Collection flagCollection = collectionOptional.get();
if (flagCollection.addAll(parsedCollection)) {
MainUtil.sendMessage(player, Captions.FLAG_ADDED);
val = flagCollection;
} else {
return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED);
}
}
}
boolean result = plot.setFlag(flag, val);
if (!result) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(player, Captions.FLAG_ADDED);
return true;
case "list":
if (!Permissions.hasPermission(player, Captions.PERMISSION_FLAG_LIST)) {
MainUtil
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_FLAG_LIST);
return false;
}
if (args.length > 1) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag list");
return false;
}
final Map<String, ArrayList<String>> flags = new HashMap<>();
for (Flag<?> flag1 : Flags.getFlags()) {
final String category = flag1.getCategoryCaption();
final Collection<String> flagList =
flags.computeIfAbsent(category, k -> new ArrayList<>());
flagList.add(flag1.getName());
}
final StringBuilder message = new StringBuilder();
final Iterator<Map.Entry<String, ArrayList<String>>> iterator =
flags.entrySet().iterator();
while (iterator.hasNext()) {
final Map.Entry<String, ArrayList<String>> flagsEntry = iterator.next();
final List<String> flagNames = flagsEntry.getValue();
Collections.sort(flagNames);
message.append(String.format(Captions.FLAG_LIST_ENTRY.formatted(),
flagsEntry.getKey(), StringMan.join(flagNames, ", ")));
if (iterator.hasNext()) {
message.append("\n");
}
}
MainUtil.sendMessage(player, message.toString());
return true;
}
MainUtil
.sendMessage(player, Captions.COMMAND_SYNTAX, getUsage());
return false;
}
}

View File

@ -0,0 +1,519 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.InternalFlag;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.flags.types.IntegerFlag;
import com.github.intellectualsites.plotsquared.plot.flags.types.ListFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.helpmenu.HelpMenu;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@CommandDeclaration(command = "flag",
aliases = {"f", "flag"},
usage = "/plot flag <set|remove|add|list|info> <flag> <value>",
description = "Manage plot flags",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag")
@SuppressWarnings("unused")
public final class FlagCommand extends Command {
public FlagCommand() {
super(MainCommand.getInstance(), true);
}
private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) {
message.send(player, args);
return true;
}
private static boolean checkPermValue(@Nonnull final PlotPlayer player,
@NotNull final PlotFlag<?, ?> flag, @NotNull String key, @NotNull String value) {
key = key.toLowerCase();
value = value.toLowerCase();
String perm = CaptionUtility
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), value.toLowerCase());
if (flag instanceof IntegerFlag && MathMan.isInteger(value)) {
try {
int numeric = Integer.parseInt(value);
perm = perm.substring(0, perm.length() - value.length() - 1);
if (numeric > 0) {
int checkRange = PlotSquared.get().getPlatform().equalsIgnoreCase("bukkit") ?
numeric :
Settings.Limit.MAX_PLOTS;
final boolean result = player.hasPermissionRange(perm, checkRange) >= numeric;
if (!result) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), value.toLowerCase()));
}
return result;
}
} catch (NumberFormatException ignore) {
}
} else if (flag instanceof ListFlag) {
final ListFlag<?, ?> listFlag = (ListFlag<?, ?>) flag;
try {
PlotFlag<? extends List<?>, ?> parsedFlag = listFlag.parse(value);
for (final Object entry : parsedFlag.getValue()) {
final String permission = CaptionUtility
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), entry.toString().toLowerCase());
final boolean result = Permissions.hasPermission(player, permission);
if (!result) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), value.toLowerCase()));
return false;
}
}
} catch (final FlagParseException e) {
MainUtil.sendMessage(player,
Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", flag.getName())
.replace("%flag_value%", e.getValue())
.replace("%error%", e.getErrorMessage()));
return false;
} catch (final Exception e) {
return false;
}
return true;
}
final boolean result = Permissions.hasPermission(player, perm);
if (!result) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_SET_FLAG_KEY_VALUE.getTranslated(),
key.toLowerCase(), value.toLowerCase()));
}
return result;
}
/**
* Checks if the player is allowed to modify the flags at their current location
*
* @return true if the player is allowed to modify the flags at their current location
*/
private static boolean checkRequirements(@NotNull final PlotPlayer player) {
final Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {
MainUtil.sendMessage(player, Captions.NOT_IN_PLOT);
return false;
}
if (!plot.hasOwner()) {
sendMessage(player, Captions.PLOT_NOT_CLAIMED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions
.hasPermission(player, Captions.PERMISSION_SET_FLAG_OTHER)) {
MainUtil
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_SET_FLAG_OTHER);
return false;
}
return true;
}
/**
* Attempt to extract the plot flag from the command arguments. If the flag cannot
* be found, a flag suggestion may be sent to the player.
*
* @param player Player executing the command
* @param arg String to extract flag from
* @return The flag, if found, else null
*/
@Nullable private static PlotFlag<?, ?> getFlag(@NotNull final PlotPlayer player,
@NotNull final String arg) {
if (arg != null && arg.length() > 0) {
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(arg);
if (flag instanceof InternalFlag || flag == null) {
boolean suggested = false;
try {
final StringComparison<PlotFlag<?, ?>> stringComparison =
new StringComparison<>(arg,
GlobalFlagContainer.getInstance().getFlagMap().values());
final String best = stringComparison.getBestMatch();
if (best != null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG_SUGGESTED, best);
suggested = true;
}
} catch (final Exception ignored) { /* Happens sometimes because of mean code */ }
if (!suggested) {
MainUtil.sendMessage(player, Captions.NOT_VALID_FLAG);
}
return null;
}
return flag;
}
return null;
}
@Override public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
if (args.length == 0 || !Arrays
.asList("set", "s", "list", "l", "delete", "remove", "r", "add", "a", "info", "i")
.contains(args[0].toLowerCase(Locale.ENGLISH))) {
new HelpMenu(player).setCategory(CommandCategory.SETTINGS)
.setCommands(this.getCommands()).generateMaxPages()
.generatePage(0, getParent().toString()).render();
return CompletableFuture.completedFuture(true);
}
return super.execute(player, args, confirm, whenDone);
}
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args,
final boolean space) {
if (args.length == 1) {
return Stream
.of("s", "set", "add", "a", "remove", "r", "delete", "info", "i", "list", "l")
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
}).collect(Collectors.toList());
} else if (Arrays.asList("s", "set", "add", "a", "remove", "r", "delete", "info", "i")
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 2) {
return GlobalFlagContainer.getInstance().getRecognizedPlotFlags().stream()
.filter(flag -> !(flag instanceof InternalFlag))
.filter(flag -> flag.getName().startsWith(args[1].toLowerCase(Locale.ENGLISH)))
.map(flag -> new Command(null, false, flag.getName(), "", RequiredType.NONE, null) {
}).collect(Collectors.toList());
} else if (Arrays.asList("s", "set", "add", "a", "remove", "r", "delete")
.contains(args[0].toLowerCase(Locale.ENGLISH)) && args.length == 3) {
try {
final PlotFlag<?, ?> flag =
GlobalFlagContainer.getInstance().getFlagFromString(args[1]);
if (flag != null) {
Stream<String> stream = flag.getTabCompletions().stream();
if (flag instanceof ListFlag && args[2].contains(",")) {
final String[] split = args[2].split(",");
// Prefix earlier values onto all suggestions
StringBuilder prefix = new StringBuilder();
for (int i = 0; i < split.length - 1; i++) {
prefix.append(split[i]).append(",");
}
final String cmp;
if (!args[2].endsWith(",")) {
cmp = split[split.length - 1];
} else {
prefix.append(split[split.length - 1]).append(",");
cmp = "";
}
return stream
.filter(value -> value.startsWith(cmp.toLowerCase(Locale.ENGLISH))).map(
value -> new Command(null, false, prefix + value, "",
RequiredType.NONE, null) {
}).collect(Collectors.toList());
} else {
return stream
.filter(value -> value.startsWith(args[2].toLowerCase(Locale.ENGLISH)))
.map(value -> new Command(null, false, value, "", RequiredType.NONE,
null) {
}).collect(Collectors.toList());
}
}
} catch (final Exception e) {
}
}
return tabOf(player, args, space);
}
@CommandDeclaration(command = "set",
aliases = {"s", "set"},
usage = "/plot flag set <flag> <value>",
description = "Set a plot flag",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.set.flag")
public void set(final Command command, final PlotPlayer player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
return;
}
if (args.length < 2) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
return;
}
final PlotFlag<?, ?> plotFlag = getFlag(player, args[0]);
if (plotFlag == null) {
return;
}
final String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
if (!checkPermValue(player, plotFlag, args[0], value)) {
return;
}
final PlotFlag<?, ?> parsed;
try {
parsed = plotFlag.parse(value);
} catch (final FlagParseException e) {
MainUtil.sendMessage(player,
Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", plotFlag.getName())
.replace("%flag_value%", e.getValue()).replace("%error%", e.getErrorMessage()));
return;
}
player.getLocation().getPlotAbs().setFlag(parsed);
MainUtil.sendMessage(player, Captions.FLAG_ADDED);
}
@CommandDeclaration(command = "add",
aliases = {"a", "add"},
usage = "/plot flag add <flag> <value>",
description = "Add a plot flag value",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.add")
public void add(final Command command, PlotPlayer player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
return;
}
if (args.length < 2) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
return;
}
final PlotFlag flag = getFlag(player, args[0]);
if (flag == null) {
return;
}
final PlotFlag localFlag =
player.getLocation().getPlotAbs().getFlagContainer().getFlag(flag.getClass());
for (String entry : args[1].split(",")) {
if (!checkPermValue(player, flag, args[0], entry)) {
return;
}
}
final String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
final PlotFlag parsed;
try {
parsed = flag.parse(value);
} catch (FlagParseException e) {
MainUtil.sendMessage(player,
Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", flag.getName())
.replace("%flag_value%", e.getValue()).replace("%error%", e.getErrorMessage()));
return;
}
boolean result =
player.getLocation().getPlotAbs().setFlag(localFlag.merge(parsed.getValue()));
if (!result) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED);
return;
}
MainUtil.sendMessage(player, Captions.FLAG_ADDED);
}
@CommandDeclaration(command = "remove",
aliases = {"r", "remove", "delete"},
usage = "/plot flag remove <flag> [values]",
description = "Remove a flag",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.add")
public void remove(final Command command, PlotPlayer player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
return;
}
if (args.length != 1 && args.length != 2) {
MainUtil
.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
return;
}
final PlotFlag<?, ?> flag = getFlag(player, args[0]);
if (flag == null) {
return;
}
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(),
args[0].toLowerCase()))) {
if (args.length != 2) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_SET_FLAG_KEY.getTranslated(),
args[0].toLowerCase()));
return;
}
}
final Plot plot = player.getLocation().getPlotAbs();
if (args.length == 2 && flag instanceof ListFlag) {
String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
final ListFlag listFlag = (ListFlag) flag;
final List list =
new ArrayList(plot.getFlag((Class<? extends ListFlag<?, ?>>) listFlag.getClass()));
final PlotFlag parsedFlag;
try {
parsedFlag = listFlag.parse(value);
} catch (final FlagParseException e) {
MainUtil.sendMessage(player,
Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", flag.getName())
.replace("%flag_value%", e.getValue())
.replace("%error%", e.getErrorMessage()));
return;
}
if (((List) parsedFlag.getValue()).isEmpty()) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return;
}
if (list.removeAll((List) parsedFlag.getValue())) {
if (list.isEmpty()) {
if (plot.removeFlag(flag)) {
MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
return;
} else {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return;
}
} else {
// MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
if (plot.setFlag(parsedFlag.createFlagInstance(list))) {
MainUtil.sendMessage(player, Captions.FLAG_PARTIALLY_REMOVED);
return;
} else {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return;
}
}
} else {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return;
}
} else {
boolean result = plot.removeFlag(flag);
if (!result) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return;
}
}
MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
}
@CommandDeclaration(command = "list",
aliases = {"l", "list", "flags"},
usage = "/plot flag list",
description = "List all available plot flags",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.list")
public void list(final Command command, final PlotPlayer player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
return;
}
final Map<String, ArrayList<String>> flags = new HashMap<>();
for (PlotFlag<?, ?> plotFlag : GlobalFlagContainer.getInstance().getRecognizedPlotFlags()) {
if (plotFlag instanceof InternalFlag) {
continue;
}
final String category = plotFlag.getFlagCategory().getTranslated();
final Collection<String> flagList =
flags.computeIfAbsent(category, k -> new ArrayList<>());
flagList.add(plotFlag.getName());
}
for (final Map.Entry<String, ArrayList<String>> entry : flags.entrySet()) {
Collections.sort(entry.getValue());
PlotMessage plotMessage = new PlotMessage(entry.getKey() + ": ")
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated());
final Iterator<String> flagIterator = entry.getValue().iterator();
while (flagIterator.hasNext()) {
final String flag = flagIterator.next();
plotMessage = plotMessage.text(flag).command("/plot flag info " + flag)
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).tooltip(
new PlotMessage(Captions.FLAG_LIST_SEE_INFO.getTranslated())
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()));
if (flagIterator.hasNext()) {
plotMessage = plotMessage.text(", ")
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated());
}
}
plotMessage.send(player);
}
}
@CommandDeclaration(command = "info",
aliases = {"i", "info"},
usage = "/plot flag info <flag>",
description = "View information about a flag",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.flag.info")
public void info(final Command command, final PlotPlayer player, final String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
if (!checkRequirements(player)) {
return;
}
if (args.length < 1) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag info <flag>");
return;
}
final PlotFlag<?, ?> plotFlag = getFlag(player, args[0]);
if (plotFlag != null) {
Captions.FLAG_INFO_HEADER.send(player);
// Flag name
new PlotMessage(Captions.FLAG_INFO_NAME.getTranslated())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(plotFlag.getName())
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
// Flag category
new PlotMessage(Captions.FLAG_INFO_CATEGORY.getTranslated())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated())
.text(plotFlag.getFlagCategory().getTranslated())
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
// Flag description
new PlotMessage(Captions.FLAG_INFO_DESCRIPTION.getTranslated())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).send(player);
new PlotMessage(plotFlag.getFlagDescription().getTranslated())
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
// Flag example
new PlotMessage(Captions.FLAG_INFO_EXAMPLE.getTranslated())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated())
.text("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample())
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated())
.suggest("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample())
.send(player);
// Default value
final String defaultValue = player.getLocation().getPlotArea().getFlagContainer()
.getFlagErased(plotFlag.getClass()).toString();
new PlotMessage(Captions.FLAG_INFO_DEFAULT_VALUE.getTranslated())
.color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(defaultValue)
.color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player);
// Footer. Done this way to prevent the duplicate-message-thingy from catching it
MainUtil.sendMessage(player, "&r" + Captions.FLAG_INFO_FOOTER.getTranslated());
}
}
}

View File

@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -16,9 +17,12 @@ import com.google.common.primitives.Ints;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "grant", category = CommandCategory.CLAIMING,
usage = "/plot grant <check|add> [player]", permission = "plots.grant",
requiredType = RequiredType.NONE) public class Grant extends Command {
@CommandDeclaration(command = "grant",
category = CommandCategory.CLAIMING,
usage = "/plot grant <check|add> [player]",
permission = "plots.grant",
requiredType = RequiredType.NONE)
public class Grant extends Command {
public Grant() {
super(MainCommand.getInstance(), true);
@ -32,10 +36,10 @@ import java.util.concurrent.CompletableFuture;
switch (arg0) {
case "add":
case "check":
if (!Permissions.hasPermission(player,
Captions.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0))) {
Captions.NO_PERMISSION.send(player,
Captions.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0));
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0))) {
Captions.NO_PERMISSION.send(player, CaptionUtility
.format(player, Captions.PERMISSION_GRANT.getTranslated(), arg0));
return CompletableFuture.completedFuture(false);
}
if (args.length > 2) {

View File

@ -13,8 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.helpmenu.HelpMenu;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "help", description = "Get this help menu", aliases = "?",
category = CommandCategory.INFO, usage = "help [category|#]", permission = "plots.use")
@CommandDeclaration(command = "help",
description = "Get this help menu",
aliases = "?",
category = CommandCategory.INFO,
usage = "help [category|#]",
permission = "plots.use")
public class Help extends Command {
public Help(Command parent) {
super(parent, true);
@ -55,7 +59,8 @@ public class Help extends Command {
return CompletableFuture.completedFuture(true);
}
public CompletableFuture<Boolean> displayHelp(final PlotPlayer player, final String catRaw, final int page) {
public CompletableFuture<Boolean> displayHelp(final PlotPlayer player, final String catRaw,
final int page) {
return CompletableFuture.supplyAsync(() -> {
String cat = catRaw;
@ -80,11 +85,10 @@ public class Help extends Command {
for (CommandCategory c : CommandCategory.values()) {
builder.append("\n").append(StringMan
.replaceAll(Captions.HELP_INFO_ITEM.getTranslated(), "%category%",
c.toString().toLowerCase(),
"%category_desc%", c.toString()));
c.toString().toLowerCase(), "%category_desc%", c.toString()));
}
builder.append("\n")
.append(Captions.HELP_INFO_ITEM.getTranslated().replaceAll("%category%", "all")
builder.append("\n").append(
Captions.HELP_INFO_ITEM.getTranslated().replaceAll("%category%", "all")
.replaceAll("%category_desc%", "Display all commands"));
builder.append("\n").append(Captions.HELP_FOOTER.getTranslated());
MainUtil.sendMessage(player, builder.toString(), false);

View File

@ -13,8 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import java.util.List;
@CommandDeclaration(command = "inbox", description = "Review the comments for a plot",
usage = "/plot inbox [inbox] [delete <index>|clear|page]", permission = "plots.inbox", category = CommandCategory.CHAT, requiredType = RequiredType.PLAYER)
@CommandDeclaration(command = "inbox",
description = "Review the comments for a plot",
usage = "/plot inbox [inbox] [delete <index>|clear|page]",
permission = "plots.inbox",
category = CommandCategory.CHAT,
requiredType = RequiredType.PLAYER)
public class Inbox extends SubCommand {
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
@ -40,8 +44,7 @@ public class Inbox extends SubCommand {
StringBuilder string = new StringBuilder();
string.append(StringMan
.replaceAll(Captions.COMMENT_LIST_HEADER_PAGED.getTranslated(), "%amount%",
comments.length, "%cur",
page + 1, "%max", totalPages + 1, "%word", "all") + '\n');
comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + '\n');
// This might work xD
for (int x = page * 12; x < max; x++) {

View File

@ -4,19 +4,17 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.HideInfoFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
import com.github.intellectualsites.plotsquared.plot.object.PlotItemStack;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import java.util.UUID;
@CommandDeclaration(command = "info", aliases = "i", description = "Display plot info",
usage = "/plot info <id> [-f, to force info]", category = CommandCategory.INFO)
@CommandDeclaration(command = "info",
aliases = "i",
description = "Display plot info",
usage = "/plot info <id> [-f, to force info]",
category = CommandCategory.INFO)
public class Info extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@ -70,7 +68,7 @@ public class Info extends SubCommand {
}
// hide-info flag
if (plot.getFlag(Flags.HIDE_INFO).orElse(false)) {
if (plot.getFlag(HideInfoFlag.class)) {
boolean allowed = false;
for (final String argument : args) {
if (argument.equalsIgnoreCase("-f")) {
@ -89,37 +87,6 @@ public class Info extends SubCommand {
}
}
if (args.length == 1 && args[0].equalsIgnoreCase("inv")) {
PlotInventory inv = new PlotInventory(player) {
@Override public boolean onClick(int index) {
// TODO InfoInventory not implemented yet!!!!!!!!
// See plot rating or musicsubcommand on examples
return false;
}
};
UUID uuid = player.getUUID();
String name = MainUtil.getName(plot.getOwner());
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info",
"&cID: &6" + plot.getId().toString(), "&cOwner:&6" + name,
"&cAlias: &6" + plot.getAlias(),
"&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(),
"&cCan Build: &6" + plot.isAdded(uuid),
"&cSeen: &6" + MainUtil.secToTime((int) (ExpireManager.IMP.getAge(plot) / 1000)),
"&cIs Denied: &6" + plot.isDenied(uuid)));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted",
"&cAmount: &6" + plot.getTrusted().size(),
"&8Click to view a list of the trusted users"));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers",
"&cAmount: &6" + plot.getMembers().size(),
"&8Click to view a list of plot members"));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", "&cDenied",
"&cAmount: &6" + plot.getDenied().size(),
"&8Click to view a list of denied players"));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", "&cFlags",
"&cAmount: &6" + plot.getFlags().size(), "&8Click to view a list of plot flags"));
inv.openInventory();
return true;
}
boolean hasOwner = plot.hasOwner();
// Wildcard player {added}
boolean containsEveryone = plot.getTrusted().contains(DBFunc.EVERYONE);
@ -130,7 +97,7 @@ public class Info extends SubCommand {
plot.getId().x + ";" + plot.getId().y);
return true;
}
String info = Captions.PLOT_INFO.getTranslated();
String info = Captions.PLOT_INFO_FORMAT.getTranslated();
boolean full;
if (arg != null) {
info = getCaption(arg);

View File

@ -17,9 +17,14 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@CommandDeclaration(command = "kick", aliases = "k", description = "Kick a player from your plot",
permission = "plots.kick", usage = "/plot kick <player|*>", category = CommandCategory.TELEPORT,
requiredType = RequiredType.PLAYER) public class Kick extends SubCommand {
@CommandDeclaration(command = "kick",
aliases = "k",
description = "Kick a player from your plot",
permission = "plots.kick",
usage = "/plot kick <player|*>",
category = CommandCategory.TELEPORT,
requiredType = RequiredType.PLAYER)
public class Kick extends SubCommand {
public Kick() {
super(Argument.PlayerName);

View File

@ -15,8 +15,11 @@ import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "leave",
description = "Removes self from being trusted or a member of the plot",
permission = "plots.leave", usage = "/plot leave", category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER) public class Leave extends Command {
permission = "plots.leave",
usage = "/plot leave",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER)
public class Leave extends Command {
public Leave() {
super(MainCommand.getInstance(), true);
}

View File

@ -5,7 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.Rating;
@ -21,9 +21,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.UUID;
@CommandDeclaration(command = "like", permission = "plots.like", description = "Like the plot",
usage = "/plot like [next|purge]", category = CommandCategory.INFO,
requiredType = RequiredType.PLAYER) public class Like extends SubCommand {
@CommandDeclaration(command = "like",
permission = "plots.like",
description = "Like the plot",
usage = "/plot like [next|purge]",
category = CommandCategory.INFO,
requiredType = RequiredType.PLAYER)
public class Like extends SubCommand {
protected static boolean handleLike(final PlotPlayer player, String[] args,
final boolean like) {
@ -41,8 +45,8 @@ import java.util.UUID;
return v2 > v1 ? 1 : -1;
});
for (final Plot plot : plots) {
if ((!Settings.Done.REQUIRED_FOR_RATINGS || plot.hasFlag(Flags.DONE))
&& plot.isBasePlot() && (!plot.getLikes().containsKey(uuid))) {
if ((!Settings.Done.REQUIRED_FOR_RATINGS || DoneFlag.isDone(plot)) && plot
.isBasePlot() && (!plot.getLikes().containsKey(uuid))) {
plot.teleportPlayer(player, TeleportCause.COMMAND);
MainUtil.sendMessage(player, Captions.RATE_THIS);
return true;
@ -78,7 +82,7 @@ import java.util.UUID;
sendMessage(player, Captions.RATING_NOT_YOUR_OWN);
return false;
}
if (Settings.Done.REQUIRED_FOR_RATINGS && !plot.hasFlag(Flags.DONE)) {
if (Settings.Done.REQUIRED_FOR_RATINGS && !DoneFlag.isDone(plot)) {
sendMessage(player, Captions.RATING_NOT_DONE);
return false;
}
@ -105,15 +109,15 @@ import java.util.UUID;
}
}
};
if (plot.getSettings().ratings == null) {
if (plot.getSettings().getRatings() == null) {
if (!Settings.Enabled_Components.RATING_CACHE) {
TaskManager.runTaskAsync(() -> {
plot.getSettings().ratings = DBFunc.getRatings(plot);
plot.getSettings().setRatings(DBFunc.getRatings(plot));
run.run();
});
return true;
}
plot.getSettings().ratings = new HashMap<>();
plot.getSettings().setRatings(new HashMap<>());
}
run.run();
return true;

View File

@ -3,8 +3,10 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.PlotSquared.SortType;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
@ -24,11 +26,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
@CommandDeclaration(command = "list", aliases = {"l", "find", "search"}, description = "List plots",
permission = "plots.list", category = CommandCategory.INFO,
@CommandDeclaration(command = "list",
aliases = {"l", "find", "search"},
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO,
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|unknown|player|world|done|fuzzy <search...>> [#]")
public class ListCmd extends SubCommand {
@ -136,11 +140,11 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_WORLD);
return false;
}
if (!Permissions
.hasPermission(player,
Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world));
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(),
world));
return false;
}
plots = new ArrayList<>(PlotSquared.get().getPlots(world));
@ -161,11 +165,11 @@ public class ListCmd extends SubCommand {
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_AREA);
return false;
}
if (!Permissions
.hasPermission(player,
Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world));
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), world))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(),
world));
return false;
}
plots = area == null ? new ArrayList<Plot>() : new ArrayList<>(area.getPlots());
@ -186,14 +190,13 @@ public class ListCmd extends SubCommand {
}
plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) {
Optional<String> flag = plot.getFlag(Flags.DONE);
if (flag.isPresent()) {
if (DoneFlag.isDone(plot)) {
plots.add(plot);
}
}
plots.sort((a, b) -> {
String va = "" + a.getFlags().get(Flags.DONE);
String vb = "" + b.getFlags().get(Flags.DONE);
String va = a.getFlag(DoneFlag.class);
String vb = b.getFlag(DoneFlag.class);
if (MathMan.isInteger(va)) {
if (MathMan.isInteger(vb)) {
return Integer.parseInt(vb) - Integer.parseInt(va);
@ -248,8 +251,7 @@ public class ListCmd extends SubCommand {
}
plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) {
Optional<Double> price = plot.getFlag(Flags.PRICE);
if (price.isPresent()) {
if (plot.getFlag(PriceFlag.class) > 0) {
plots.add(plot);
}
}
@ -309,11 +311,12 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_WORLD);
return false;
}
if (!Permissions
.hasPermission(player, Captions
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0]))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(), args[0]));
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(),
args[0]))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_LIST_WORLD_NAME.getTranslated(),
args[0]));
return false;
}
plots = new ArrayList<>(PlotSquared.get().getPlots(args[0]));
@ -383,18 +386,10 @@ public class ListCmd extends SubCommand {
Captions.PLOT_INFO_MEMBERS.getTranslated()
.replaceAll("%members%", MainUtil.getPlayerList(plot.getMembers()))))
.color("$1");
String strFlags = StringMan.join(plot.getFlags().values(), ",");
if (strFlags.isEmpty()) {
strFlags = Captions.NONE.getTranslated();
}
PlotMessage flags = new PlotMessage().text(Captions.color(
Captions.PLOT_INFO_FLAGS.getTranslated().replaceAll("%flags%", strFlags)))
.color("$1");
message.text("[").color("$3").text(i + "")
.command("/plot visit " + plot.getArea() + ";" + plot.getId())
.tooltip("/plot visit " + plot.getArea() + ";" + plot.getId()).color("$1")
.text("]").color("$3").text(" " + plot.toString())
.tooltip(trusted, members, flags)
.text("]").color("$3").text(" " + plot.toString()).tooltip(trusted, members)
.command("/plot info " + plot.getArea() + ";" + plot.getId()).color(color)
.text(" - ").color("$2");
String prefix = "";

View File

@ -19,9 +19,14 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
@CommandDeclaration(command = "load", aliases = "restore", category = CommandCategory.SCHEMATIC,
requiredType = RequiredType.NONE, description = "Load your plot", permission = "plots.load",
usage = "/plot load") public class Load extends SubCommand {
@CommandDeclaration(command = "load",
aliases = "restore",
category = CommandCategory.SCHEMATIC,
requiredType = RequiredType.NONE,
description = "Load your plot",
permission = "plots.load",
usage = "/plot load")
public class Load extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
String world = player.getLocation().getWorld();

View File

@ -79,15 +79,14 @@ public class MainCommand extends Command {
new DebugClaimTest();
new Inbox();
new Comment();
new Database();
new DatabaseCommand();
new Swap();
new Music();
new DebugRoadRegen();
new Trust();
new DebugExec();
new FlagCmd();
new FlagCommand();
new Target();
new DebugFixFlags();
new Move();
new Condense();
new Copy();
@ -206,7 +205,8 @@ public class MainCommand extends Command {
PlotArea area = player.getApplicablePlotArea();
Plot newPlot = Plot.fromString(area, args[0]);
if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea()
.equals(area) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_SUDO_AREA))
.equals(area) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN)
|| Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_SUDO_AREA))
&& !newPlot.isDenied(player.getUUID())) {
Location newLoc = newPlot.getCenter();
if (player.canTeleport(newLoc)) {

View File

@ -20,10 +20,14 @@ import java.util.UUID;
import static com.github.intellectualsites.plotsquared.plot.object.Direction.getFromIndex;
@CommandDeclaration(command = "merge", aliases = "m",
@CommandDeclaration(command = "merge",
aliases = "m",
description = "Merge the plot you are standing on with another plot",
permission = "plots.merge", usage = "/plot merge <all|n|e|s|w> [removeroads]",
category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, confirmation = true)
permission = "plots.merge",
usage = "/plot merge <all|n|e|s|w> [removeroads]",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
confirmation = true)
public class Merge extends SubCommand {
public static final String[] values = new String[] {"north", "east", "south", "west", "auto"};
@ -160,8 +164,7 @@ public class Merge extends SubCommand {
}
Plot adjacent = plot.getRelative(direction);
if (adjacent == null || !adjacent.hasOwner() || adjacent
.getMerged((direction.getIndex() + 2) % 4)
|| adjacent.isOwner(uuid)) {
.getMerged((direction.getIndex() + 2) % 4) || adjacent.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.NO_AVAILABLE_AUTOMERGE);
return false;
}

View File

@ -10,10 +10,13 @@ import com.github.intellectualsites.plotsquared.plot.object.TeleportCause;
/**
* @author manuelgu, altered by Citymonstret
*/
@CommandDeclaration(command = "middle", aliases = {"center", "centre"},
description = "Teleports you to the center of the plot", usage = "/plot middle",
category = CommandCategory.TELEPORT, requiredType = RequiredType.PLAYER) public class Middle
extends SubCommand {
@CommandDeclaration(command = "middle",
aliases = {"center", "centre"},
description = "Teleports you to the center of the plot",
usage = "/plot middle",
category = CommandCategory.TELEPORT,
requiredType = RequiredType.PLAYER)
public class Middle extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] arguments) {
Location location = player.getLocation();

View File

@ -10,9 +10,13 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
@CommandDeclaration(usage = "/plot move <X;Z>", command = "move", description = "Move a plot",
permission = "plots.move", category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER) public class Move extends SubCommand {
@CommandDeclaration(usage = "/plot move <X;Z>",
command = "move",
description = "Move a plot",
permission = "plots.move",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER)
public class Move extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
Location location = player.getLocation();

View File

@ -2,7 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
@ -14,10 +15,13 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;
@CommandDeclaration(command = "music", permission = "plots.music",
description = "Play music in your plot", usage = "/plot music",
category = CommandCategory.APPEARANCE, requiredType = RequiredType.PLAYER) public class Music
extends SubCommand {
@CommandDeclaration(command = "music",
permission = "plots.music",
description = "Play music in your plot",
usage = "/plot music",
category = CommandCategory.APPEARANCE,
requiredType = RequiredType.PLAYER)
public class Music extends SubCommand {
private static final Collection<String> DISCS = Arrays
.asList("music_disc_13", "music_disc_cat", "music_disc_blocks", "music_disc_chirp",
@ -41,10 +45,11 @@ import java.util.Locale;
return true;
}
if (item.getType() == ItemTypes.BEDROCK) {
plot.removeFlag(Flags.MUSIC);
plot.removeFlag(MusicFlag.class);
Captions.FLAG_REMOVED.send(player);
} else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) {
plot.setFlag(Flags.MUSIC, item.getType().getId());
plot.setFlag(GlobalFlagContainer.getInstance().getFlag(MusicFlag.class)
.createFlagInstance(item.getType()));
Captions.FLAG_ADDED.send(player);
} else {
Captions.FLAG_NOT_ADDED.send(player);

View File

@ -11,8 +11,12 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "near", aliases = "n", description = "Display nearby players",
usage = "/plot near", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER)
@CommandDeclaration(command = "near",
aliases = "n",
description = "Display nearby players",
usage = "/plot near",
category = CommandCategory.INFO,
requiredType = RequiredType.PLAYER)
public class Near extends Command {
public Near() {
super(MainCommand.getInstance(), true);

View File

@ -14,10 +14,15 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import java.util.Set;
import java.util.UUID;
@CommandDeclaration(command = "setowner", permission = "plots.set.owner",
description = "Set the plot owner", usage = "/plot setowner <player>",
aliases = {"owner", "so", "seto"}, category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE, confirmation = true) public class Owner extends SetCommand {
@CommandDeclaration(command = "setowner",
permission = "plots.set.owner",
description = "Set the plot owner",
usage = "/plot setowner <player>",
aliases = {"owner", "so", "seto"},
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
confirmation = true)
public class Owner extends SetCommand {
@Override public boolean set(final PlotPlayer player, final Plot plot, String value) {
if (value == null || value.isEmpty()) {

View File

@ -8,15 +8,23 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import static com.github.intellectualsites.plotsquared.plot.util.PremiumVerification.isPremium;
@CommandDeclaration(command = "plugin", permission = "plots.use",
description = "Show plugin information", usage = "/plot plugin", aliases = "version",
category = CommandCategory.INFO) public class PluginCmd extends SubCommand {
@CommandDeclaration(command = "plugin",
permission = "plots.use",
description = "Show plugin information",
usage = "/plot plugin",
aliases = "version",
category = CommandCategory.INFO)
public class PluginCmd extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
TaskManager.IMP.taskAsync(() -> {
MainUtil.sendMessage(player, String.format("$2>> $1&l" + PlotSquared.imp().getPluginName() + " $2($1Version$2: $1%s$2)", PlotSquared.get().getVersion()));
MainUtil.sendMessage(player, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21 $2& $1NotMyFault");
MainUtil.sendMessage(player, "$2>> $1&lWiki$2: $1https://github.com/IntellectualSites/PlotSquared/wiki");
MainUtil.sendMessage(player, String.format(
"$2>> $1&l" + PlotSquared.imp().getPluginName() + " $2($1Version$2: $1%s$2)",
PlotSquared.get().getVersion()));
MainUtil.sendMessage(player,
"$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21 $2& $1NotMyFault");
MainUtil.sendMessage(player,
"$2>> $1&lWiki$2: $1https://github.com/IntellectualSites/PlotSquared/wiki");
MainUtil.sendMessage(player, "$2>> $1&lPremium$2: $1" + isPremium());
});
return true;

View File

@ -18,11 +18,14 @@ import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
@CommandDeclaration(
usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]",
command = "purge", permission = "plots.admin", description = "Purge all plots for a world",
category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE,
confirmation = true) public class Purge extends SubCommand {
@CommandDeclaration(usage = "/plot purge world:<world> area:<area> id:<id> owner:<owner> shared:<shared> unknown:[true|false]",
command = "purge",
permission = "plots.admin",
description = "Purge all plots for a world",
category = CommandCategory.ADMINISTRATION,
requiredType = RequiredType.CONSOLE,
confirmation = true)
public class Purge extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length == 0) {

View File

@ -6,7 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
import com.github.intellectualsites.plotsquared.plot.object.PlotItemStack;
@ -24,9 +24,14 @@ import java.util.HashMap;
import java.util.Map.Entry;
import java.util.UUID;
@CommandDeclaration(command = "rate", permission = "plots.rate", description = "Rate the plot",
usage = "/plot rate [#|next|purge]", aliases = "rt", category = CommandCategory.INFO,
requiredType = RequiredType.PLAYER) public class Rate extends SubCommand {
@CommandDeclaration(command = "rate",
permission = "plots.rate",
description = "Rate the plot",
usage = "/plot rate [#|next|purge]",
aliases = "rt",
category = CommandCategory.INFO,
requiredType = RequiredType.PLAYER)
public class Rate extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length == 1) {
@ -53,7 +58,7 @@ import java.util.UUID;
});
UUID uuid = player.getUUID();
for (Plot p : plots) {
if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE)) && p
if ((!Settings.Done.REQUIRED_FOR_RATINGS || DoneFlag.isDone(p)) && p
.isBasePlot() && (!p.getRatings().containsKey(uuid)) && !p
.isAdded(uuid)) {
p.teleportPlayer(player, TeleportCause.COMMAND);
@ -91,7 +96,7 @@ import java.util.UUID;
sendMessage(player, Captions.RATING_NOT_YOUR_OWN);
return false;
}
if (Settings.Done.REQUIRED_FOR_RATINGS && !plot.hasFlag(Flags.DONE)) {
if (Settings.Done.REQUIRED_FOR_RATINGS && !DoneFlag.isDone(plot)) {
sendMessage(player, Captions.RATING_NOT_DONE);
return false;
}
@ -146,15 +151,15 @@ import java.util.UUID;
inventory.openInventory();
}
};
if (plot.getSettings().ratings == null) {
if (plot.getSettings().getRatings() == null) {
if (!Settings.Enabled_Components.RATING_CACHE) {
TaskManager.runTaskAsync(() -> {
plot.getSettings().ratings = DBFunc.getRatings(plot);
plot.getSettings().setRatings(DBFunc.getRatings(plot));
run.run();
});
return true;
}
plot.getSettings().ratings = new HashMap<>();
plot.getSettings().setRatings(new HashMap<>());
}
run.run();
return true;
@ -187,15 +192,15 @@ import java.util.UUID;
sendMessage(player, Captions.RATING_APPLIED, plot.getId().toString());
}
};
if (plot.getSettings().ratings == null) {
if (plot.getSettings().getRatings() == null) {
if (!Settings.Enabled_Components.RATING_CACHE) {
TaskManager.runTaskAsync(() -> {
plot.getSettings().ratings = DBFunc.getRatings(plot);
plot.getSettings().setRatings(DBFunc.getRatings(plot));
run.run();
});
return true;
}
plot.getSettings().ratings = new HashMap<>();
plot.getSettings().setRatings(new HashMap<>());
}
run.run();
return true;

View File

@ -12,9 +12,12 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@CommandDeclaration(command = "regenallroads",
description = "Regenerate all roads in the map using the set road schematic",
aliases = {"rgar"}, usage = "/plot regenallroads <world> [height]",
category = CommandCategory.ADMINISTRATION, requiredType = RequiredType.CONSOLE,
permission = "plots.regenallroads") public class RegenAllRoads extends SubCommand {
aliases = {"rgar"},
usage = "/plot regenallroads <world> [height]",
category = CommandCategory.ADMINISTRATION,
requiredType = RequiredType.CONSOLE,
permission = "plots.regenallroads")
public class RegenAllRoads extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
int height = 0;

View File

@ -13,8 +13,12 @@ import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "relight", description = "Relight your plot", usage = "/plot relight",
category = CommandCategory.DEBUG, requiredType = RequiredType.PLAYER) public class Relight extends Command {
@CommandDeclaration(command = "relight",
description = "Relight your plot",
usage = "/plot relight",
category = CommandCategory.DEBUG,
requiredType = RequiredType.PLAYER)
public class Relight extends Command {
public Relight() {
super(MainCommand.getInstance(), true);
}

View File

@ -12,9 +12,13 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import java.io.IOException;
import java.util.Objects;
@CommandDeclaration(command = "reload", aliases = "rl", permission = "plots.admin.command.reload",
description = "Reload translations and world settings", usage = "/plot reload",
category = CommandCategory.ADMINISTRATION) public class Reload extends SubCommand {
@CommandDeclaration(command = "reload",
aliases = "rl",
permission = "plots.admin.command.reload",
description = "Reload translations and world settings",
usage = "/plot reload",
category = CommandCategory.ADMINISTRATION)
public class Reload extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
try {

View File

@ -17,10 +17,14 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@CommandDeclaration(command = "remove", aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"},
description = "Remove a player from a plot", usage = "/plot remove <player|*>",
category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE,
permission = "plots.remove") public class Remove extends SubCommand {
@CommandDeclaration(command = "remove",
aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"},
description = "Remove a player from a plot",
usage = "/plot remove <player|*>",
category = CommandCategory.SETTINGS,
requiredType = RequiredType.NONE,
permission = "plots.remove")
public class Remove extends SubCommand {
public Remove() {
super(Argument.PlayerName);

View File

@ -18,9 +18,13 @@ import java.net.URL;
import java.util.List;
import java.util.UUID;
@CommandDeclaration(command = "save", aliases = {"backup"}, description = "Save your plot",
category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE,
permission = "plots.save") public class Save extends SubCommand {
@CommandDeclaration(command = "save",
aliases = {"backup"},
description = "Save your plot",
category = CommandCategory.SCHEMATIC,
requiredType = RequiredType.NONE,
permission = "plots.save")
public class Save extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
String world = player.getLocation().getWorld();

View File

@ -23,9 +23,12 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
@CommandDeclaration(command = "schematic", permission = "plots.schematic",
description = "Schematic command", aliases = {"sch", "schem"},
category = CommandCategory.SCHEMATIC, usage = "/plot schematic <save|saveall|paste>")
@CommandDeclaration(command = "schematic",
permission = "plots.schematic",
description = "Schematic command",
aliases = {"sch", "schem"},
category = CommandCategory.SCHEMATIC,
usage = "/plot schematic <save|saveall|paste>")
public class SchematicCmd extends SubCommand {
private boolean running = false;
@ -136,7 +139,8 @@ public class SchematicCmd extends SubCommand {
return false;
} else {
MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_STARTED);
MainUtil.sendMessage(player, "&3Plot&8->&3Schematic&8: &7Found &c" + plots.size() + "&7 plots...");
MainUtil.sendMessage(player,
"&3Plot&8->&3Schematic&8: &7Found &c" + plots.size() + "&7 plots...");
}
break;
}

View File

@ -2,10 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -19,16 +17,18 @@ import com.sk89q.worldedit.function.pattern.Pattern;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@CommandDeclaration(command = "set", description = "Set a plot value", aliases = {"s"},
usage = "/plot set <biome|alias|home|flag> <value...>", permission = "plots.set",
category = CommandCategory.APPEARANCE, requiredType = RequiredType.NONE) public class Set
extends SubCommand {
@CommandDeclaration(command = "set",
description = "Set a plot value",
aliases = {"s"},
usage = "/plot set <biome|alias|home|flag> <value...>",
permission = "plots.set",
category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE)
public class Set extends SubCommand {
public static final String[] values = new String[] {"biome", "alias", "home", "flag"};
public static final String[] aliases = new String[] {"b", "w", "wf", "f", "a", "h", "fl"};
public static final String[] values = new String[] {"biome", "alias", "home"};
public static final String[] aliases = new String[] {"b", "w", "wf", "a", "h"};
private final SetCommand component;
@ -50,9 +50,10 @@ import java.util.stream.IntStream;
for (String component : components) {
if (component.equalsIgnoreCase(args[0])) {
if (!Permissions.hasPermission(player, Captions
.format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(), component))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(),
component))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_SET_COMPONENT.getTranslated(),
component));
return false;
@ -82,15 +83,13 @@ import java.util.stream.IntStream;
}
public boolean noArgs(PlotPlayer player) {
ArrayList<String> newValues =
new ArrayList<>(Arrays.asList("biome", "alias", "home", "flag"));
ArrayList<String> newValues = new ArrayList<>(Arrays.asList("biome", "alias", "home"));
Plot plot = player.getCurrentPlot();
if (plot != null) {
newValues.addAll(
Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
}
MainUtil
.sendMessage(player, Captions.SUBCOMMAND_SET_OPTIONS_HEADER.getTranslated() + StringMan
MainUtil.sendMessage(player,
Captions.SUBCOMMAND_SET_OPTIONS_HEADER.getTranslated() + StringMan
.join(newValues, Captions.BLOCK_LIST_SEPARATOR.formatted()));
return false;
}
@ -114,22 +113,11 @@ import java.util.stream.IntStream;
return false;
}
// components
HashSet<String> components = new HashSet<>(
Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
HashSet<String> components =
new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getId())));
if (components.contains(args[0].toLowerCase())) {
return this.component.onCommand(player, Arrays.copyOfRange(args, 0, args.length));
}
// flag
Flag<?> flag = FlagManager.getFlag(args[0].toLowerCase());
if (Flags.getFlags().contains(flag)) {
String a = "";
if (args.length > 1) {
a = IntStream.range(1, args.length).mapToObj(x -> " " + args[x])
.collect(Collectors.joining());
}
MainCommand.onCommand(player, ("flag set " + args[0] + a).split(" "));
return true;
}
return noArgs(player);
}
}

View File

@ -1,5 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
@ -17,21 +18,21 @@ public abstract class SetCommand extends SubCommand {
return !sendMessage(player, Captions.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (!Permissions
.hasPermission(player,
Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()));
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(),
getFullId()));
MainUtil.sendMessage(player, Captions.PLOT_NOT_CLAIMED);
return false;
}
}
if (!plot.isOwner(player.getUUID())) {
if (!Permissions
.hasPermission(player,
Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()));
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility
.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(),
getFullId()));
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}

View File

@ -8,9 +8,13 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@CommandDeclaration(command = "sethome", permission = "plots.set.home",
description = "Set the plot home to your current position", usage = "/plot sethome [none]",
aliases = {"sh", "seth"}, category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER)
@CommandDeclaration(command = "sethome",
permission = "plots.set.home",
description = "Set the plot home to your current position",
usage = "/plot sethome [none]",
aliases = {"sh", "seth"},
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class SetHome extends SetCommand {
@Override public boolean set(PlotPlayer player, Plot plot, String value) {

View File

@ -34,9 +34,19 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
@CommandDeclaration(command = "setup", permission = "plots.admin.command.setup",
description = "Setup wizard for plot worlds", usage = "/plot setup", aliases = {"create"},
category = CommandCategory.ADMINISTRATION) public class Setup extends SubCommand {
@CommandDeclaration(command = "setup",
permission = "plots.admin.command.setup",
description = "Setup wizard for plot worlds",
usage = "/plot setup",
aliases = {"create"},
category = CommandCategory.ADMINISTRATION)
public class Setup extends SubCommand {
private static boolean d(String s) {
return s.chars().allMatch((i) -> {
return i == 95 || i == 45 || i >= 97 && i <= 122 || i >= 48 && i <= 57 || i == 46;
});
}
public void displayGenerators(PlotPlayer player) {
StringBuilder message = new StringBuilder();
@ -336,11 +346,7 @@ import java.util.UUID;
return false;
}
private static boolean d(String s) {
return s.chars().allMatch((i) -> {
return i == 95 || i == 45 || i >= 97 && i <= 122 || i >= 48 && i <= 57 || i == 46;
});
}
private static final class StepPickGenerator extends SetupStep {
@Getter private String generator;
@ -414,7 +420,7 @@ import java.util.UUID;
}
@Override public boolean parseInput(String input) {
if (!WORLD_TYPES.keySet().contains(input.toLowerCase())) {
if (!WORLD_TYPES.containsKey(input.toLowerCase())) {
return false;
}
this.worldType = input.toLowerCase();
@ -427,7 +433,9 @@ import java.util.UUID;
}
@ToString @EqualsAndHashCode(of = "uuid") @AllArgsConstructor
@ToString
@EqualsAndHashCode(of = "uuid")
@AllArgsConstructor
private static class SetupContext {
private final UUID uuid;

View File

@ -8,8 +8,12 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
@CommandDeclaration(usage = "/plot swap <X;Z>", command = "swap", description = "Swap two plots",
aliases = {"switch"}, category = CommandCategory.CLAIMING, requiredType = RequiredType.PLAYER)
@CommandDeclaration(usage = "/plot swap <X;Z>",
command = "swap",
description = "Swap two plots",
aliases = {"switch"},
category = CommandCategory.CLAIMING,
requiredType = RequiredType.PLAYER)
public class Swap extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {

View File

@ -10,10 +10,13 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
@CommandDeclaration(command = "target", usage = "/plot target <<plot>|nearest>",
description = "Target a plot with your compass", permission = "plots.target",
requiredType = RequiredType.PLAYER, category = CommandCategory.INFO) public class Target
extends SubCommand {
@CommandDeclaration(command = "target",
usage = "/plot target <<plot>|nearest>",
description = "Target a plot with your compass",
permission = "plots.target",
requiredType = RequiredType.PLAYER,
category = CommandCategory.INFO)
public class Target extends SubCommand {
public Target() {
super(Argument.PlotID);

View File

@ -29,10 +29,12 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
@CommandDeclaration(command = "template", permission = "plots.admin",
@CommandDeclaration(command = "template",
permission = "plots.admin",
description = "Create or use a world template",
usage = "/plot template [import|export] <world> <template>",
category = CommandCategory.ADMINISTRATION) public class Template extends SubCommand {
category = CommandCategory.ADMINISTRATION)
public class Template extends SubCommand {
public static boolean extractAllFiles(String world, String template) {
try {

View File

@ -8,16 +8,22 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
@CommandDeclaration(command = "toggle", aliases = {"attribute"}, permission = "plots.use",
@CommandDeclaration(command = "toggle",
aliases = {"attribute"},
permission = "plots.use",
usage = "/plot toggle <chat|chatspy|clear-confirmation|time|titles|worldedit>",
description = "Toggle per user settings", requiredType = RequiredType.NONE,
category = CommandCategory.SETTINGS) public class Toggle extends Command {
description = "Toggle per user settings",
requiredType = RequiredType.NONE,
category = CommandCategory.SETTINGS)
public class Toggle extends Command {
public Toggle() {
super(MainCommand.getInstance(), true);
}
@CommandDeclaration(command = "chatspy", aliases = {"spy"},
permission = "plots.admin.command.chat", description = "Toggle plot chat spy")
@CommandDeclaration(command = "chatspy",
aliases = {"spy"},
permission = "plots.admin.command.chat",
description = "Toggle plot chat spy")
public void chatspy(Command command, PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
@ -28,8 +34,10 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
}
}
@CommandDeclaration(command = "worldedit", aliases = {"we", "wea"},
permission = "plots.worldedit.bypass", description = "Toggle worldedit area restrictions")
@CommandDeclaration(command = "worldedit",
aliases = {"we", "wea"},
permission = "plots.worldedit.bypass",
description = "Toggle worldedit area restrictions")
public void worldedit(Command command, PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
@ -40,7 +48,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
}
}
@CommandDeclaration(command = "chat", permission = "plots.toggle.chat",
@CommandDeclaration(command = "chat",
permission = "plots.toggle.chat",
description = "Toggle plot chat")
public void chat(Command command, PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
@ -53,7 +62,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
}
@CommandDeclaration(command = "clear-confirmation",
permission = "plots.admin.command.autoclear", description = "Toggle autoclear confirmation")
permission = "plots.admin.command.autoclear",
description = "Toggle autoclear confirmation")
public void clearConfirmation(Command command, PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
@ -64,7 +74,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
}
}
@CommandDeclaration(command = "titles", permission = "plots.toggle.titles",
@CommandDeclaration(command = "titles",
permission = "plots.toggle.titles",
description = "Toggle plot title messages")
public void titles(Command command, PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
@ -76,7 +87,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
}
}
@CommandDeclaration(command = "time", permission = "plots.toggle.time",
@CommandDeclaration(command = "time",
permission = "plots.toggle.time",
description = "Toggle plot time settings")
public void time(Command command, PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,

View File

@ -30,10 +30,13 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@CommandDeclaration(command = "trim", permission = "plots.admin",
@CommandDeclaration(command = "trim",
permission = "plots.admin",
description = "Delete unmodified portions of your plotworld",
usage = "/plot trim <world> [regenerate]", requiredType = RequiredType.CONSOLE,
category = CommandCategory.ADMINISTRATION) public class Trim extends SubCommand {
usage = "/plot trim <world> [regenerate]",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.ADMINISTRATION)
public class Trim extends SubCommand {
public static ArrayList<Plot> expired = null;
private static volatile boolean TASK = false;
@ -177,18 +180,20 @@ import java.util.Set;
}
int bx = cbx << 4;
int bz = cbz << 4;
CuboidRegion region = RegionUtil.createRegion(bx, bx + 511, bz, bz + 511);
CuboidRegion region =
RegionUtil.createRegion(bx, bx + 511, bz, bz + 511);
for (Plot plot : PlotSquared.get().getPlots(world)) {
Location bot = plot.getBottomAbs();
Location top = plot.getExtendedTopAbs();
CuboidRegion plotReg =
RegionUtil.createRegion(bot.getX(), top.getX(), bot.getZ(),
top.getZ());
CuboidRegion plotReg = RegionUtil
.createRegion(bot.getX(), top.getX(), bot.getZ(), top.getZ());
if (!RegionUtil.intersects(region, plotReg)) {
continue;
}
for (int x = plotReg.getMinimumPoint().getX() >> 4; x <= plotReg.getMaximumPoint().getX() >> 4; x++) {
for (int z = plotReg.getMinimumPoint().getZ() >> 4; z <= plotReg.getMaximumPoint().getZ() >> 4; z++) {
for (int x = plotReg.getMinimumPoint().getX() >> 4;
x <= plotReg.getMaximumPoint().getX() >> 4; x++) {
for (int z = plotReg.getMinimumPoint().getZ() >> 4;
z <= plotReg.getMaximumPoint().getZ() >> 4; z++) {
BlockVector2 loc = BlockVector2.at(x, z);
chunks.remove(loc);
}

View File

@ -17,10 +17,13 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "trust", aliases = {"t"}, requiredType = RequiredType.PLAYER,
@CommandDeclaration(command = "trust",
aliases = {"t"},
requiredType = RequiredType.PLAYER,
usage = "/plot trust <player|*>",
description = "Allow a user to build in a plot and use WorldEdit while the plot owner is offline.",
category = CommandCategory.SETTINGS) public class Trust extends Command {
category = CommandCategory.SETTINGS)
public class Trust extends Command {
public Trust() {
super(MainCommand.getInstance(), true);

View File

@ -11,9 +11,13 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
@CommandDeclaration(command = "unlink", aliases = {"u", "unmerge"},
description = "Unlink a mega-plot", usage = "/plot unlink [createroads]",
requiredType = RequiredType.PLAYER, category = CommandCategory.SETTINGS, confirmation = true)
@CommandDeclaration(command = "unlink",
aliases = {"u", "unmerge"},
description = "Unlink a mega-plot",
usage = "/plot unlink [createroads]",
requiredType = RequiredType.PLAYER,
category = CommandCategory.SETTINGS,
confirmation = true)
public class Unlink extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {

View File

@ -5,7 +5,7 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -24,10 +24,14 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "visit", permission = "plots.visit",
description = "Visit someones plot", usage = "/plot visit [<player>|<alias>|<world>|<id>] [#]",
aliases = {"v", "tp", "teleport", "goto", "home", "h", "warp"}, requiredType = RequiredType.PLAYER,
category = CommandCategory.TELEPORT) public class Visit extends Command {
@CommandDeclaration(command = "visit",
permission = "plots.visit",
description = "Visit someones plot",
usage = "/plot visit [<player>|<alias>|<world>|<id>] [#]",
aliases = {"v", "tp", "teleport", "goto", "home", "h", "warp"},
requiredType = RequiredType.PLAYER,
category = CommandCategory.TELEPORT)
public class Visit extends Command {
public Visit() {
super(MainCommand.getInstance(), true);
@ -139,8 +143,8 @@ import java.util.concurrent.CompletableFuture;
return CompletableFuture.completedFuture(false);
}
} else {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER) &&
!Flags.UNTRUSTED_VISIT.isTrue(plot)) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER) && !plot
.getFlag(UntrustedVisitFlag.class)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER);
return CompletableFuture.completedFuture(false);
}

View File

@ -3,9 +3,13 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@CommandDeclaration(command = "weanywhere", permission = "plots.worldedit.bypass",
description = "Force bypass of WorldEdit restrictions", aliases = {"wea"}, usage = "/plot weanywhere",
requiredType = RequiredType.NONE, category = CommandCategory.ADMINISTRATION)
@CommandDeclaration(command = "weanywhere",
permission = "plots.worldedit.bypass",
description = "Force bypass of WorldEdit restrictions",
aliases = {"wea"},
usage = "/plot weanywhere",
requiredType = RequiredType.NONE,
category = CommandCategory.ADMINISTRATION)
@Deprecated
public class WE_Anywhere extends SubCommand {

View File

@ -0,0 +1,30 @@
package com.github.intellectualsites.plotsquared.plot.config;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
public interface Caption {
String getTranslated();
default String formatted() {
return StringMan.replaceFromMap(getTranslated(), Captions.replacements);
}
default void send(PlotPlayer caller, String... args) {
send(caller, (Object[]) args);
}
default void send(PlotPlayer caller, Object... args) {
String msg = CaptionUtility.format(caller, this, args);
if (caller == null) {
PlotSquared.log(msg);
} else {
caller.sendMessage(msg);
}
}
boolean usePrefix();
}

View File

@ -0,0 +1,31 @@
package com.github.intellectualsites.plotsquared.plot.config;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
public class CaptionUtility {
public static String formatRaw(PlotPlayer recipient, String message, Object... args) {
final ChatFormatter.ChatContext chatContext = new ChatFormatter.ChatContext(recipient, message, args, true);
for (final ChatFormatter chatFormatter : ChatFormatter.formatters) {
chatFormatter.format(chatContext);
}
return chatContext.getMessage();
}
public static String format(PlotPlayer recipient, String message, Object... args) {
final ChatFormatter.ChatContext chatContext = new ChatFormatter.ChatContext(recipient, message, args, false);
for (final ChatFormatter chatFormatter : ChatFormatter.formatters) {
chatFormatter.format(chatContext);
}
return chatContext.getMessage();
}
public static String format(PlotPlayer recipient, Caption caption, Object... args) {
if (caption.usePrefix() && caption.getTranslated().length() > 0) {
return Captions.PREFIX.getTranslated() + format(recipient, caption.getTranslated(), args);
} else {
return format(recipient, caption.getTranslated(), args);
}
}
}

View File

@ -3,7 +3,6 @@ package com.github.intellectualsites.plotsquared.plot.config;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import java.io.File;
@ -16,7 +15,7 @@ import java.util.Set;
/**
* Captions class.
*/
public enum Captions {
public enum Captions implements Caption {
//@formatter:off
//<editor-fold desc="Static Flags">
@ -445,6 +444,9 @@ public enum Captions {
NOT_VALID_NUMBER("$2That's not a valid number within the range: %s", "Invalid"),
NOT_VALID_PLOT_ID("$2That's not a valid plot id.", "Invalid"),
FOUND_NO_PLOTS("$2Found no plots with your search query", "Invalid"),
NUMBER_NOT_IN_RANGE("That's not a valid number within the range: (%s, %s)", "Invalid"),
NUMBER_NOT_POSITIVE("That's not a positive number: %s", "Invalid"),
NOT_A_NUMBER("%s is not a valid number.", "Invalid"),
//</editor-fold>
//<editor-fold desc="Need">
NEED_BLOCK("$2You've got to specify a block", "Need"),
@ -463,10 +465,11 @@ public enum Captions {
PLOT_INFO_UNCLAIMED("$2Plot $1%s$2 is not yet claimed", "Info"),
PLOT_INFO_HEADER("$3&m---------&r $1INFO $3&m---------", false, "Info"),
PLOT_INFO_HIDDEN("$2You cannot view the information about this plot", "Info"),
PLOT_INFO("$1ID: $2%id%$1&-" + "$1Alias:$2%alias%$1&-" + "$1Owner:$2%owner%$1&-"
PLOT_INFO_FORMAT("$1ID: $2%id%$1&-" + "$1Area: $2%area%$1&-"
+"$1Alias:$2%alias%$1&-" + "$1Owner:$2%owner%$1&-"
+ "$1Biome: $2%biome%$1&-" + "$1Can Build: $2%build%$1&-" + "$1Rating: $2%rating%&-"
+ "$1Seen: $2%seen%&-" + "$1Trusted:$2%trusted%$1&-" + "$1Members:$2%members%$1&-"
+ "$1Denied:$2%denied%$1&-" + "$1Flags:$2%flags%", "Info"),
+ "$1Denied:$2%denied%$1&-" + "$1Flags:$2%flags%&-$1Description: $2%desc%$1", "Info"),
PLOT_INFO_FOOTER("$3&m---------&r $1INFO $3&m---------", false, "Info"),
PLOT_INFO_TRUSTED("$1Trusted:$2%trusted%", "Info"),
PLOT_INFO_MEMBERS("$1Members:$2%members%", "Info"),
@ -481,7 +484,8 @@ public enum Captions {
PLOT_INFO_SIZE("$1Size:$2 %size%", "Info"),
PLOT_INFO_SEEN("$1Seen:$2 %seen%", "Info"),
PLOT_USER_LIST(" $1%user%$2,", "Info"),
PLOT_FLAG_LIST("$1%s0:%s1$2", "Info"),
PLOT_FLAG_LIST("$2%s0:%s1$3", "Info"),
PLOT_NO_DESCRIPTION("No description set.", "Info"),
INFO_SYNTAX_CONSOLE("$2/plot info X;Z", "Info"),
//</editor-fold>
//<editor-fold desc="Working">
@ -527,16 +531,32 @@ public enum Captions {
FLAG_NOT_REMOVED("$2The flag could not be removed", "Flag"),
FLAG_NOT_ADDED("$2The flag could not be added", "Flag"),
FLAG_REMOVED("$4Successfully removed flag", "Flag"),
FLAG_PARTIALLY_REMOVED("$4Successfully removed flag value(s)", "Flag"),
FLAG_ADDED("$4Successfully added flag", "Flag"),
FLAG_TUTORIAL_USAGE("$1Have an admin set the flag: $2%s", "CommandConfig"),
FLAG_LIST_ENTRY("$2%s: $1%s", "Flag"),
FLAG_LIST_SEE_INFO("Click to view information about the flag", "Flag"),
FLAG_PARSE_ERROR("$2Failed to parse flag '%flag_name%', value '%flag_value%': %error%", "Flag"),
//</editor-fold>
//<editor-fold desc="Flag">
FLAG_INFO_HEADER("$3&m---------&r $1Plot² Flags $3&m---------", "Flag"),
FLAG_INFO_FOOTER("$3&m---------&r $1Plot² Flags $3&m---------", "Flag"),
FLAG_INFO_COLOR_KEY("$1", "Flag"),
FLAG_INFO_COLOR_VALUE("$2", "Flag"),
FLAG_INFO_NAME("Name: ", "Flag"),
FLAG_INFO_CATEGORY("Category: ", "Flag"),
FLAG_INFO_DESCRIPTION("Description: ", "Flag"),
FLAG_INFO_EXAMPLE("Example: ", "Flag"),
FLAG_INFO_DEFAULT_VALUE("Default Value: ", "Flag"),
//</editor-fold>
//<editor-fold desc="Flag category captions">
FLAG_CATEGORY_STRING("String Flags", "Flags"),
FLAG_CATEGORY_INTEGERS("Integer Flags", "Flags"),
FLAG_CATEGORY_DOUBLES("Decimal Flags", "Flags"),
FLAG_CATEGORY_TELEPORT_DENY("Teleport Deny Flag", "Flags"),
FLAG_CATEGORY_STRING_LIST("String List Flags", "Flags"),
FLAG_CATEGORY_WEATHER("Weather Flags", "Flags"),
FLAG_CATEGORY_MUSIC("Music Flags", "Flags"),
FLAG_CATEGORY_BLOCK_LIST("Material Flags", "Flags"),
FLAG_CATEGORY_INTERVALS("Interval Flags", "Flags"),
FLAG_CATEGORY_INTEGER_LIST("Integer List Flags", "Flags"),
@ -546,20 +566,97 @@ public enum Captions {
FLAG_CATEGORY_BOOLEAN("Boolean Flags", "Flags"),
FLAG_CATEGORY_MIXED("Mixed Value Flags", "Flags"),
//</editor-fold>
//<editor-fold desc="Flag descriptions">
FLAG_DESCRIPTION_ENTITY_CAP("Set to an integer value to limit the amount of entities on the plot.", "Flags"),
FLAG_DESCRIPTION_EXPLOSION("Set to `true` to enable explosions in the plot, and `false` to disable them.", "Flags"),
FLAG_DESCRIPTION_MUSIC("Set to a music disk ID (item name) to play the music disc inside of the plot.", "Flags"),
FLAG_DESCRIPTION_FLIGHT("Set to `true` to enable flight within the plot when in survival or adventure mode.", "Flags"),
FLAG_DESCRIPTION_UNTRUSTED("Set to `false` to disallow untrusted players from visiting the plot.", "Flags"),
FLAG_DESCRIPTION_DENY_EXIT("Set to `true` to disallow players from exiting the plot.", "Flags"),
FLAG_DESCRIPTION_DESCRIPTION("Plot description. Supports '&' color codes.", "Flags"),
FLAG_DESCRIPTION_GREETING("Message sent to players on plot entry. Supports '&' color codes.", "Flags"),
FLAG_DESCRIPTION_FAREWELL("Message sent to players when leaving the plot. Supports '&' color codes.", "Flags"),
FLAG_DESCRIPTION_WEATHER("Specifies the weather conditions inside of the plot.", "Flags"),
FLAG_DESCRIPTION_ANIMAL_ATTACK("Set to `true` to allow animals to be attacked in the plot.", "Flags"),
FLAG_DESCRIPTION_ANIMAL_CAP("Set to an integer value to limit the amount of animals on the plot.", "Flags"),
FLAG_DESCRIPTION_ANIMAL_INTERACT("Set to `true` to allow animals to be interacted with in the plot.", "Flags"),
FLAG_DESCRIPTION_BLOCK_BURN("Set to `true` to allow blocks to burn within the plot.", "Flags"),
FLAG_DESCRIPTION_BLOCK_IGNITION("Set to `false` to prevent blocks from igniting within the plot.", "Flags"),
FLAG_DESCRIPTION_BREAK("Define a list of materials players should be able to break even when they aren't added to the plot.", "Flags"),
FLAG_DESCRIPTION_DEVICE_INTERACT("Set to `true` to allow devices to be interacted with in the plot.", "Flags"),
FLAG_DESCRIPTION_DISABLE_PHYSICS("Set to `true` to disable block physics in the plot.", "Flags"),
FLAG_DESCRIPTION_DROP_PROTECTION("Set to `true` to prevent dropped items from being picked up by non-members of the plot.", "Flags"),
FLAG_DESCRIPTION_FEED("Specify an interval in seconds and an optional amount by which the players will be fed (amount is 1 by default).", "Flags"),
FLAG_DESCRIPTION_FORCEFIELD("Set to `true` to enable member forcefield in the plot.", "Flags"),
FLAG_DESCRIPTION_GRASS_GROW("Set to `false` to prevent grass from growing within the plot.", "Flags"),
FLAG_DESCRIPTION_HANGING_BREAK("Set to `true` to allow guests to break hanging objects in the plot.", "Flags"),
FLAG_DESCRIPTION_HANGING_PLACE("Set to `true` to allow guests to hang objects in the plot.", "Flags"),
FLAG_DESCRIPTION_HEAL("Specify an interval in seconds and an optional amount by which the players will be healed (amount is 1 by default).", "Flags"),
FLAG_DESCRIPTION_HIDE_INFO("Set to `true` to hide plot information.", "Flags"),
FLAG_DESCRIPTION_HOSTILE_ATTACK("Set to `true` to enable players to attack hostile mobs in the plot.", "Flags"),
FLAG_DESCRIPTION_HOSTILE_CAP("Set to an integer value to limit the amount of hostile entities on the plot.", "Flags"),
FLAG_DESCRIPTION_HOSTILE_INTERACT("Set to `true` to allow players to interact with hostile mobs in the plot.", "Flags"),
FLAG_DESCRIPTION_ICE_FORM("Set to `true` to allow ice to form in the plot.", "Flags"),
FLAG_DESCRIPTION_ICE_MELT("Set to `false` to disable ice melting in the plot.", "Flags"),
FLAG_DESCRIPTION_INSTABREAK("Set to `true` to allow blocks to be instantaneously broken in survival mode.", "Flags"),
FLAG_DESCRIPTION_INVINCIBLE("Set to `true` to prevent players from taking damage inside of the plot.", "Flags"),
FLAG_DESCRIPTION_ITEM_DROP("Set to `false` to prevent items from being dropped inside of the plot.", "Flags"),
FLAG_DESCRIPTION_KELP_GROW("Set to `false` to prevent kelp from growing in the plot.", "Flags"),
FLAG_DESCRIPTION_LIQUID_FLOW("Set to `false` to disable liquids from flowing within the plot.", "Flags"),
FLAG_DESCRIPTION_MISC_BREAK("Set to `true` to allow guests to break miscellaneous items.", "Flags"),
FLAG_DESCRIPTION_MISC_CAP("Set to an integer value to limit the amount of miscellaneous entities on the plot.", "Flags"),
FLAG_DESCRIPTION_MISC_INTERACT("Set to `true` to allow guests to interact with miscellaneous items.", "Flags"),
FLAG_DESCRIPTION_MISC_PLACE("Set to `true` to allow guests to place miscellaneous items.", "Flags"),
FLAG_DESCRIPTION_MOB_BREAK("Set to `true` to allow mobs to break blocks within the plot.", "Flags"),
FLAG_DESCRIPTION_MOB_CAP("Set to an integer value to limit the amount of mobs on the plot.", "Flags"),
FLAG_DESCRIPTION_MOB_PLACE("Set to `true` to allow mobs to place blocks within the plot.", "Flags"),
FLAG_DESCRIPTION_MYCEL_GROW("Set to `false` to prevent mycelium from growing in the plot.", "Flags"),
FLAG_DESCRIPTION_NOTIFY_ENTER("Set to `true` to notify the plot owners when someone enters the plot.", "Flags"),
FLAG_DESCRIPTION_NOTIFY_LEAVE("Set to `true` to notify the plot owners when someone leaves the plot.", "Flags"),
FLAG_DESCRIPTION_NO_WORLDEDIT("Set to `true` to disable WorldEdit usage within the plot.", "Flags"),
FLAG_DESCRIPTION_PLACE("Define a list of materials players should be able to place in the plot.", "Flags"),
FLAG_DESCRIPTION_PLAYER_INTERACT("Set to `true` to allow guests to interact with players in the plot.", "Flags"),
FLAG_DESCRIPTION_PRICE("Set a price for a plot. Must be a positive decimal number.", "Flags"),
FLAG_DESCRIPTION_PVE("Set to `true` to enable PVE inside the plot.", "Flags"),
FLAG_DESCRIPTION_PVP("Set to `true` to enable PVP inside the plot.", "Flags"),
FLAG_DESCRIPTION_REDSTONE("Set to `false` to disable redstone in the plot.", "Flags"),
FLAG_DESCRIPTION_SERVER_PLOT("Set to `true` to turn the plot into a server plot. This is equivalent to setting the server as the plot owner.", "Flags"),
FLAG_DESCRIPTION_SNOW_FORM("Set to `true` to allow snow to form within the plot.", "Flags"),
FLAG_DESCRIPTION_SNOW_MELT("Set to `true` to allow snow to melt within the plot.", "Flags"),
FLAG_DESCRIPTION_SOIL_DRY("Set to `true` to allow soil to dry within the plot.", "Flags"),
FLAG_DESCRIPTION_TAMED_ATTACK("Set to `true` to allow guests to attack tamed animals in the plot.", "Flags"),
FLAG_DESCRIPTION_TAMED_INTERACT("Set to `true` to allow guests to interact with tamed animals in the plot.", "Flags"),
FLAG_DESCRIPTION_TIME("Set the time in the plot to a fixed value.", "Flags"),
FLAG_DESCRIPTION_TITLES("Set to `false` to disable plot titles. Can be set to: `none` (to inherit world settings), `true`, or `false`", "Flags"),
FLAG_DESCRIPTION_USE("Define a list of materials players should be able to interact with in the plot.", "Flags"),
FLAG_DESCRIPTION_VEHICLE_BREAK("Set to `true` to allow guests to break vehicles in the plot.", "Flags"),
FLAG_DESCRIPTION_VEHICLE_CAP("Set to an integer value to limit the amount of vehicles on the plot.", "Flags"),
FLAG_DESCRIPTION_VEHICLE_PLACE("Set to `true` to allow guests to place vehicles in the plot.", "Flags"),
FLAG_DESCRIPTION_VEHICLE_USE("Set to `true` to allow guests to use vehicles in the plot.", "Flags"),
FLAG_DESCRIPTION_VILLAGER_INTERACT("Set to `true` to allow guests to interact with villagers in the plot.", "Flags"),
FLAG_DESCRIPTION_VINE_GROW("Set to `false` to prevent vines from growing within the plot.", "Flags"),
FLAG_DESCRIPTION_DENY_TELEPORT("Deny a certain group from teleporting to the plot. Available groups: members, nonmembers, trusted, nontrusted, nonowners", "Flags"),
FLAG_DESCRIPTION_GAMEMODE("Determines the gamemode in the plot.", "Flags"),
FLAG_DESCRIPTION_GUEST_GAMEMODE("Determines the guest gamemode in the plot.", "Flags"),
FLAG_DESCRIPTION_BLOCKED_CMDS("A list of commands that are blocked in the plot.", "Flags"),
FLAG_DESCRIPTION_KEEP("Prevents the plot from expiring. Can be set to: true, false, the number of milliseconds to keep the plot for or a timestamp (3w 2d 5h).", "Flags"),
//</editor-fold>
//<editor-fold desc="Flag category errors">
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
FLAG_ERROR_ENUM("Must be one of: %s", "Flags"),
FLAG_ERROR_GAMEMODE("Flag value must be a gamemode: 'survival', 'creative', 'adventure' or 'spectator.", "Flags"),
FLAG_ERROR_INTEGER("Flag value must be a whole number", "Flags"),
FLAG_ERROR_INTEGER_LIST("Flag value must be an integer list", "Flags"),
FLAG_ERROR_INTERVAL("Value(s) must be numeric. /plot set flag <flag> <interval> [amount]", "Flags"),
FLAG_ERROR_KEEP("Flag value must be a timestamp or a boolean", "Flags"),
FLAG_ERROR_LONG("Flag value must be a whole number (large numbers allowed)", "Flags"),
FLAG_ERROR_PLOTBLOCKLIST("Flag value must be a block list", "Flags"),
FLAG_ERROR_PRICE("Flag value must be a positive number.", "Flags"),
FLAG_ERROR_STRING("Flag value must be alphanumeric. Some special characters are allowed.", "Flags"),
FLAG_ERROR_STRINGLIST("Flag value must be a string list", "Flags"),
FLAG_ERROR_WEATHER("Flag must be a weather: 'rain' or 'sun'", "Flags"),
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", false, "Flags"),
FLAG_ERROR_ENUM("Must be one of: %s", false, "Flags"),
FLAG_ERROR_GAMEMODE("Flag value must be a gamemode: 'survival', 'creative', 'adventure' or 'spectator.", false, "Flags"),
FLAG_ERROR_INTEGER("Flag value must be a whole number", false, "Flags"),
FLAG_ERROR_INTEGER_LIST("Flag value must be an integer list", false, "Flags"),
FLAG_ERROR_INTERVAL("Value(s) must be numeric. /plot set flag <flag> <interval> [amount]", false, "Flags"),
FLAG_ERROR_KEEP("Flag value must be a timestamp or a boolean", false, "Flags"),
FLAG_ERROR_LONG("Flag value must be a whole number (large numbers allowed)", false, "Flags"),
FLAG_ERROR_PLOTBLOCKLIST("Flag value must be a block list", false, "Flags"),
FLAG_ERROR_INVALID_BLOCK("The provided value is not a valid block or block category", false, "Flags"),
FLAG_ERROR_DOUBLE("Flag value must be a decimal number.", false, "Flags"),
FLAG_ERROR_STRING("Flag value must be alphanumeric. Some special characters are allowed.", false, "Flags"),
FLAG_ERROR_STRINGLIST("Flag value must be a string list", false, "Flags"),
FLAG_ERROR_WEATHER("Flag must be a weather: 'rain' or 'sun'", false, "Flags"),
FLAG_ERROR_MUSIC("Flag value must be a valid music disc ID.", false, "Flags"),
//</editor-fold>
//<editor-fold desc="Trusted">
TRUSTED_ADDED("$4You successfully trusted a user to the plot", "Trusted"),
@ -653,30 +750,6 @@ public enum Captions {
this(defaultString, true, category.toLowerCase());
}
public static String formatRaw(PlotPlayer recipient, String message, Object... args) {
final ChatFormatter.ChatContext chatContext = new ChatFormatter.ChatContext(recipient, message, args, true);
for (final ChatFormatter chatFormatter : ChatFormatter.formatters) {
chatFormatter.format(chatContext);
}
return chatContext.getMessage();
}
public static String format(PlotPlayer recipient, String message, Object... args) {
final ChatFormatter.ChatContext chatContext = new ChatFormatter.ChatContext(recipient, message, args, false);
for (final ChatFormatter chatFormatter : ChatFormatter.formatters) {
chatFormatter.format(chatContext);
}
return chatContext.getMessage();
}
public static String format(PlotPlayer recipient, Captions caption, Object... args) {
if (caption.usePrefix() && caption.translatedString.length() > 0) {
return Captions.PREFIX.getTranslated() + format(recipient, caption.translatedString, args);
} else {
return format(recipient, caption.translatedString, args);
}
}
public static String color(String string) {
return StringMan.replaceFromMap(string, replacements);
}
@ -767,11 +840,7 @@ public enum Captions {
}
}
@Override public String toString() {
return this.translatedString;
}
public String getTranslated() {
@Override public String getTranslated() {
return this.translatedString;
}
@ -779,24 +848,12 @@ public enum Captions {
return this.prefix;
}
public String formatted() {
return StringMan.replaceFromMap(getTranslated(), replacements);
}
public String getCategory() {
return this.category;
}
public void send(PlotPlayer caller, String... args) {
send(caller, (Object[]) args);
@Override public String toString() {
return this.getTranslated();
}
public void send(PlotPlayer caller, Object... args) {
String msg = format(caller, this, args);
if (caller == null) {
PlotSquared.log(msg);
} else {
caller.sendMessage(msg);
}
}
}

View File

@ -19,8 +19,9 @@ public class Settings extends Config {
@Comment("Show additional information in console") public static boolean DEBUG = false;
@Comment({"The big annoying text that appears when you enter a plot",
"For a single plot: `/plot flag set titles false`", "For just you: `/plot toggle titles`", "For all plots: Add `titles: false` in the worlds.yml flags block"})
public static boolean TITLES = true;
"For a single plot: `/plot flag set titles false`", "For just you: `/plot toggle titles`",
"For all plots: Add `titles: false` in the worlds.yml flags block"}) public static boolean
TITLES = true;
@Create // This value will be generated automatically
public static ConfigBlock<Auto_Clear> AUTO_CLEAR = null;
@ -220,8 +221,7 @@ public class Settings extends Config {
@Comment("Schematic Settings") public static final class Schematics {
@Comment(
"Whether schematic based generation should paste schematic on top of plots, or from Y=1")
@Comment("Whether schematic based generation should paste schematic on top of plots, or from Y=1")
public static boolean PASTE_ON_TOP = true;
}
@ -247,11 +247,12 @@ public class Settings extends Config {
public static final class Done {
@Comment("Require a plot marked as done to download") public static boolean REQUIRED_FOR_DOWNLOAD =
false;
@Comment("Only plots marked as done can be rated") public static boolean REQUIRED_FOR_RATINGS = false;
@Comment("Restrict building when a plot is marked as done") public static boolean RESTRICT_BUILDING =
false;
@Comment("Require a plot marked as done to download") public static boolean
REQUIRED_FOR_DOWNLOAD = false;
@Comment("Only plots marked as done can be rated") public static boolean
REQUIRED_FOR_RATINGS = false;
@Comment("Restrict building when a plot is marked as done") public static boolean
RESTRICT_BUILDING = false;
@Comment("The limit being how many plots a player can claim") public static boolean
COUNTS_TOWARDS_LIMIT = true;
}
@ -267,9 +268,10 @@ public class Settings extends Config {
@Comment("Relating to how many plots someone can claim ") public static final class Limit {
@Comment("Should the limit be global (over multiple worlds)") public static boolean GLOBAL =
false;
@Comment({"The max. range of permissions to check e.g. plots.plot.127", "The value covers the range to check only, you need to assign the permission to players/groups still",
"Modifying the value does NOT change the amount of plots players can claim"}) public static int
MAX_PLOTS = 127;
@Comment({"The max. range of permissions to check e.g. plots.plot.127",
"The value covers the range to check only, you need to assign the permission to players/groups still",
"Modifying the value does NOT change the amount of plots players can claim"})
public static int MAX_PLOTS = 127;
}
@ -283,7 +285,9 @@ public class Settings extends Config {
@Comment("Teleport to your plot on death") public static boolean ON_DEATH = false;
@Comment("Teleport to your plot on login") public static boolean ON_LOGIN = false;
@Comment("Teleport to your plot on claim") public static boolean ON_CLAIM = true;
@Comment({"Add a delay to all teleport commands", "Assign `plots.teleport.delay.bypass` to bypass the cooldown."}) public static int DELAY = 0;
@Comment({"Add a delay to all teleport commands",
"Assign `plots.teleport.delay.bypass` to bypass the cooldown."}) public static int
DELAY = 0;
@Comment("The visit command is ordered by world instead of globally") public static boolean
PER_WORLD_VISIT = false;
}
@ -294,8 +298,7 @@ public class Settings extends Config {
false;
@Comment("Disable redstone when all owners/trusted/members are offline")
public static boolean DISABLE_OFFLINE = false;
@Comment(
"Detect and cancel invalid pistons on the edge of plots (e.g. placed with WorldEdit)")
@Comment("Detect and cancel invalid pistons on the edge of plots (e.g. placed with WorldEdit)")
public static boolean DETECT_INVALID_EDGE_PISTONS = false;
}
@ -313,8 +316,8 @@ public class Settings extends Config {
}
@Comment(
{"Enable or disable parts of the plugin", "Note: A cache will use some memory if enabled"})
@Comment({"Enable or disable parts of the plugin",
"Note: A cache will use some memory if enabled"})
public static final class Enabled_Components { // Group the following values into a new config section
@Comment("The database stores all the plots") public static boolean DATABASE = true;
@Comment("Events are needed to track a lot of things") public static boolean EVENTS = true;
@ -345,8 +348,6 @@ public class Settings extends Config {
@Comment("Actively purge invalid database entries") public static boolean DATABASE_PURGER =
false;
@Comment("Delete plots when a player is banned") public static boolean BAN_DELETER = false;
@Comment({"Prevent possibly unsafe blocks from being used in plot components", "Can be bypassed with `/plot debugallowunsafe`"})
public static boolean PREVENT_UNSAFE = true;
@Comment("Allows PlaceholderAPI placeholders to be used in captions, flags, etc")
public static boolean EXTERNAL_PLACEHOLDERS = true;
}

View File

@ -0,0 +1,22 @@
package com.github.intellectualsites.plotsquared.plot.config;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor public final class StaticCaption implements Caption {
private final String value;
private final boolean usePrefix;
public StaticCaption(final String value) {
this(value, true);
}
@Override public String getTranslated() {
return this.value;
}
@Override public boolean usePrefix() {
return this.usePrefix;
}
}

View File

@ -1,6 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.database;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotCluster;
@ -113,6 +113,8 @@ public interface AbstractDB {
*/
int getClusterId(PlotCluster cluster);
boolean convertFlags();
/**
* @return A linked HashMap containing all plots
*/
@ -145,12 +147,20 @@ public interface AbstractDB {
void swapPlots(Plot plot1, Plot plot2);
/**
* Sets plot flags.
* Sets plot flag.
*
* @param plot Plot Object
* @param flags flags to set
* @param flag Flag to set
*/
void setFlags(Plot plot, HashMap<Flag<?>, Object> flags);
void setFlag(Plot plot, PlotFlag<?, ?> flag);
/**
* Remove a plot flag.
*
* @param plot Plot Object
* @param flag Flag to remove
*/
void removeFlag(Plot plot, PlotFlag<?, ?> flag);
/**
* Renames a cluster to the given name.

View File

@ -1,6 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.database;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotCluster;
@ -84,6 +84,7 @@ public class DBFunc {
//TODO Consider Removal
/**
* Check if a {@link ResultSet} contains a column.
*
@ -302,11 +303,18 @@ public class DBFunc {
DBFunc.dbManager.setMerged(plot, merged);
}
public static void setFlags(Plot plot, HashMap<Flag<?>, Object> flags) {
public static void setFlag(Plot plot, PlotFlag<?, ?> flag) {
if (plot.temp == -1 || dbManager == null) {
return;
}
DBFunc.dbManager.setFlags(plot, flags);
DBFunc.dbManager.setFlag(plot, flag);
}
public static void removeFlag(Plot plot, PlotFlag<?, ?> flag) {
if (plot.temp == -1 || dbManager == null) {
return;
}
DBFunc.dbManager.removeFlag(plot, flag);
}
/**

View File

@ -2,10 +2,13 @@ package com.github.intellectualsites.plotsquared.plot.database;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.config.Storage;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
import com.github.intellectualsites.plotsquared.plot.flags.GlobalFlagContainer;
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
import com.github.intellectualsites.plotsquared.plot.object.BlockLoc;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
@ -30,6 +33,7 @@ import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -540,13 +544,15 @@ import java.util.concurrent.atomic.AtomicInteger;
try {
// Create the plots
createPlots(myList, () -> {
final Map<PlotId, Integer> idMap = new HashMap<>();
try {
// Creating datastructures
HashMap<PlotId, Plot> plotMap = new HashMap<>();
for (Plot plot : myList) {
plotMap.put(plot.getId(), plot);
}
ArrayList<SettingsPair> settings = new ArrayList<>();
ArrayList<LegacySettings> settings = new ArrayList<>();
final ArrayList<UUIDPair> helpers = new ArrayList<>();
final ArrayList<UUIDPair> trusted = new ArrayList<>();
final ArrayList<UUIDPair> denied = new ArrayList<>();
@ -561,8 +567,9 @@ import java.util.concurrent.atomic.AtomicInteger;
int y = result.getInt("plot_id_z");
PlotId plotId = new PlotId(x, y);
Plot plot = plotMap.get(plotId);
idMap.put(plotId, id);
if (plot != null) {
settings.add(new SettingsPair(id, plot.getSettings()));
settings.add(new LegacySettings(id, plot.getSettings()));
for (UUID uuid : plot.getDenied()) {
denied.add(new UUIDPair(id, uuid));
}
@ -575,7 +582,10 @@ import java.util.concurrent.atomic.AtomicInteger;
}
}
}
createSettings(settings, () -> createTiers(helpers, "helpers",
createFlags(idMap, myList, () ->
createSettings(settings,
() -> createTiers(helpers, "helpers",
() -> createTiers(trusted, "trusted",
() -> createTiers(denied, "denied", () -> {
try {
@ -586,10 +596,10 @@ import java.util.concurrent.atomic.AtomicInteger;
if (whenDone != null) {
whenDone.run();
}
}))));
})))));
} catch (SQLException e) {
e.printStackTrace();
PlotSquared.debug("&7[WARN] Failed to set all helpers for plots");
PlotSquared.debug("&7[WARN] Failed to set all flags and member tiers for plots");
try {
SQLManager.this.connection.commit();
} catch (SQLException e1) {
@ -653,6 +663,34 @@ import java.util.concurrent.atomic.AtomicInteger;
setBulk(myList, mod, whenDone);
}
public void createFlags(Map<PlotId, Integer> ids, List<Plot> plots, Runnable whenDone) {
try (final PreparedStatement preparedStatement =
this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) {
for (final Plot plot : plots) {
final FlagContainer flagContainer = plot.getFlagContainer();
for (final PlotFlag<?,?> flagEntry : flagContainer.getFlagMap().values()) {
preparedStatement.setInt(1, ids.get(plot.getId()));
preparedStatement.setString(2, flagEntry.getName());
preparedStatement.setString(3, flagEntry.toString());
preparedStatement.addBatch();
}
try {
preparedStatement.executeBatch();
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store flag values for plot with entry ID: " + plot.getId());
e.printStackTrace();
continue;
}
PlotSquared.debug(Captions.PREFIX.getTranslated() + "- Finished converting flags for plot with entry ID: " + plot.getId());
}
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store flag values:");
e.printStackTrace();
}
PlotSquared.log(Captions.PREFIX.getTranslated() + "Finished converting flags (" + plots.size() + " plots processed)");
whenDone.run();
}
/**
* Create a plot
*
@ -828,111 +866,71 @@ import java.util.concurrent.atomic.AtomicInteger;
}
}
public void createSettings(final ArrayList<SettingsPair> myList, final Runnable whenDone) {
final StmtMod<SettingsPair> mod = new StmtMod<SettingsPair>() {
@Override public String getCreateMySQL(int size) {
return getCreateMySQL(size, "INSERT INTO `" + SQLManager.this.prefix
+ "plot_settings`(`plot_plot_id`,`biome`,`rain`,`custom_time`,`time`,`deny_entry`,`alias`,`flags`,`merged`,"
+ "`position`) VALUES ", 10);
}
public void createSettings(final ArrayList<LegacySettings> myList, final Runnable whenDone) {
try (final PreparedStatement preparedStatement =
this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_settings`"
+ "(`plot_plot_id`,`biome`,`rain`,`custom_time`,`time`,`deny_entry`,`alias`,`merged`,`position`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
@Override public String getCreateSQLite(int size) {
return getCreateSQLite(size, "INSERT INTO `" + SQLManager.this.prefix
+ "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS "
+ "`deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position`",
10);
}
@Override public String getCreateSQL() {
return "INSERT INTO `" + SQLManager.this.prefix
+ "plot_settings`(`plot_plot_id`) VALUES(?)";
}
@Override public void setMySQL(PreparedStatement statement, int i, SettingsPair pair)
throws SQLException {
statement.setInt(i * 10 + 1, pair.id); // id
statement.setNull(i * 10 + 2, 4); // biome
statement.setNull(i * 10 + 3, 4); // rain
statement.setNull(i * 10 + 4, 4); // custom_time
statement.setNull(i * 10 + 5, 4); // time
statement.setNull(i * 10 + 6, 4); // deny_entry
if (pair.settings.getAlias().isEmpty()) {
statement.setNull(i * 10 + 7, 4);
int packet;
if (this.mySQL) {
packet = Math.min(myList.size(), 5000);
} else {
statement.setString(i * 10 + 7, pair.settings.getAlias());
packet = Math.min(myList.size(), 50);
}
StringBuilder flag_string = new StringBuilder();
int k = 0;
for (Entry<Flag<?>, ?> flag : pair.settings.flags.entrySet()) {
if (k != 0) {
flag_string.append(',');
int totalUpdated = 0;
int updated = 0;
for (final LegacySettings legacySettings : myList) {
preparedStatement.setInt(1, legacySettings.id);
preparedStatement.setNull(2, 4);
preparedStatement.setNull(3, 4);
preparedStatement.setNull(4, 4);
preparedStatement.setNull(5, 4);
preparedStatement.setNull(6, 4);
if (legacySettings.settings.getAlias().isEmpty()) {
preparedStatement.setNull(7, 4);
} else {
preparedStatement.setString(7, legacySettings.settings.getAlias());
}
flag_string.append(flag.getKey().getName()).append(':').append(
flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯")
.replaceAll(",", "´"));
k++;
}
statement.setString(i * 10 + 8, flag_string.toString());
boolean[] merged = pair.settings.getMerged();
boolean[] merged = legacySettings.settings.getMerged();
int hash = MainUtil.hash(merged);
statement.setInt(i * 10 + 9, hash);
BlockLoc loc = pair.settings.getPosition();
preparedStatement.setInt(8, hash);
BlockLoc loc = legacySettings.settings.getPosition();
String position;
if (loc.getY() == 0) {
position = "DEFAULT";
} else {
position = loc.getX() + "," + loc.getY() + ',' + loc.getZ();
}
statement.setString(i * 10 + 10, position);
preparedStatement.setString( 9, position);
preparedStatement.addBatch();
if (++updated >= packet) {
try {
preparedStatement.executeBatch();
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store settings values for plot with entry ID: " + legacySettings.id);
e.printStackTrace();
continue;
}
}
totalUpdated += 1;
}
@Override public void setSQLite(PreparedStatement stmt, int i, SettingsPair pair)
throws SQLException {
stmt.setInt(i * 10 + 1, pair.id); // id
stmt.setNull(i * 10 + 2, 4); // biome
stmt.setNull(i * 10 + 3, 4); // rain
stmt.setNull(i * 10 + 4, 4); // custom_time
stmt.setNull(i * 10 + 5, 4); // time
stmt.setNull(i * 10 + 6, 4); // deny_entry
if (pair.settings.getAlias().isEmpty()) {
stmt.setNull(i * 10 + 7, 4);
} else {
stmt.setString(i * 10 + 7, pair.settings.getAlias());
if (totalUpdated < myList.size()) {
try {
preparedStatement.executeBatch();
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store settings values");
e.printStackTrace();
}
StringBuilder flag_string = new StringBuilder();
int k = 0;
for (Entry<Flag<?>, ?> flag : pair.settings.flags.entrySet()) {
if (k != 0) {
flag_string.append(',');
}
flag_string.append(flag.getKey().getName()).append(':').append(
flag.getKey().valueToString(flag.getValue()).replaceAll(":", "¯")
.replaceAll(",", "´"));
k++;
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store settings values:");
e.printStackTrace();
}
stmt.setString(i * 10 + 8, flag_string.toString());
boolean[] merged = pair.settings.getMerged();
int n = 0;
for (int j = 0; j < 4; ++j) {
n = (n << 1) + (merged[j] ? 1 : 0);
}
stmt.setInt(i * 10 + 9, n);
BlockLoc loc = pair.settings.getPosition();
String position;
if (loc.getY() == 0) {
position = "DEFAULT";
} else {
position = loc.getX() + "," + loc.getY() + ',' + loc.getZ();
}
stmt.setString(i * 10 + 10, position);
}
@Override public void setSQL(PreparedStatement stmt, SettingsPair pair)
throws SQLException {
stmt.setInt(1, pair.id);
}
};
addGlobalTask(() -> setBulk(myList, mod, whenDone));
PlotSquared.log(Captions.PREFIX.getTranslated() + "Finished converting settings (" + myList.size() + " plots processed)");
whenDone.run();
}
public void createEmptySettings(final ArrayList<Integer> myList, final Runnable whenDone) {
@ -944,7 +942,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Override public String getCreateSQLite(int size) {
return getCreateSQLite(size, "INSERT INTO `" + SQLManager.this.prefix
+ "plot_settings` SELECT ? AS `plot_plot_id`, ? AS `biome`, ? AS `rain`, ? AS `custom_time`, ? AS `time`, ? AS "
+ "`deny_entry`, ? AS `alias`, ? AS `flags`, ? AS `merged`, ? AS `position` ",
+ "`deny_entry`, ? AS `alias`, ? AS `merged`, ? AS `position` ",
10);
}
@ -968,8 +966,7 @@ import java.util.concurrent.atomic.AtomicInteger;
stmt.setNull(i * 10 + 6, 4);
stmt.setNull(i * 10 + 7, 4);
stmt.setNull(i * 10 + 8, 4);
stmt.setNull(i * 10 + 9, 4);
stmt.setString(i * 10 + 10, "DEFAULT");
stmt.setString(i * 10 + 9, "DEFAULT");
}
@Override public void setSQL(PreparedStatement stmt, Integer id) throws SQLException {
@ -1098,7 +1095,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Override public void createTables() throws SQLException {
String[] tables =
new String[] {"plot", "plot_denied", "plot_helpers", "plot_comments", "plot_trusted",
"plot_rating", "plot_settings", "cluster", "player_meta"};
"plot_rating", "plot_settings", "cluster", "player_meta", "plot_flags"};
DatabaseMetaData meta = this.connection.getMetaData();
int create = 0;
for (String s : tables) {
@ -1142,7 +1139,7 @@ import java.util.concurrent.atomic.AtomicInteger;
+ " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0,"
+ " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000',"
+ " `deny_entry` TINYINT(1) DEFAULT '0',"
+ " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL,"
+ " `alias` VARCHAR(50) DEFAULT NULL,"
+ " `merged` INT(11) DEFAULT NULL,"
+ " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT',"
+ " PRIMARY KEY (`plot_plot_id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
@ -1173,7 +1170,7 @@ import java.util.concurrent.atomic.AtomicInteger;
+ " `cluster_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST',"
+ " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0',"
+ " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0',"
+ " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL,"
+ " `alias` VARCHAR(50) DEFAULT NULL,"
+ " `merged` INT(11) DEFAULT NULL,"
+ " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT',"
+ " PRIMARY KEY (`cluster_id`)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
@ -1182,6 +1179,12 @@ import java.util.concurrent.atomic.AtomicInteger;
+ " `uuid` VARCHAR(40) NOT NULL," + " `key` VARCHAR(32) NOT NULL,"
+ " `value` blob NOT NULL," + " PRIMARY KEY (`meta_id`)"
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_flags`("
+ "`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
+ "`plot_id` INT(11) NOT NULL," + " `flag` VARCHAR(256)," + " `value` VARCHAR(512),"
+ "FOREIGN KEY (plot_id) REFERENCES `" + this.prefix + "plot` (id) ON DELETE CASCADE, "
+ "UNIQUE (plot_id, flag)"
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
} else {
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` ("
+ "`id` INTEGER PRIMARY KEY AUTOINCREMENT," + "`plot_id_x` INT(11) NOT NULL,"
@ -1207,7 +1210,7 @@ import java.util.concurrent.atomic.AtomicInteger;
+ " `biome` VARCHAR(45) DEFAULT 'FOREST'," + " `rain` INT(1) DEFAULT 0,"
+ " `custom_time` TINYINT(1) DEFAULT '0'," + " `time` INT(11) DEFAULT '8000',"
+ " `deny_entry` TINYINT(1) DEFAULT '0',"
+ " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL,"
+ " `alias` VARCHAR(50) DEFAULT NULL,"
+ " `merged` INT(11) DEFAULT NULL,"
+ " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT',"
+ " PRIMARY KEY (`plot_plot_id`)" + ')');
@ -1229,7 +1232,7 @@ import java.util.concurrent.atomic.AtomicInteger;
+ " `cluster_id` INT(11) NOT NULL," + " `biome` VARCHAR(45) DEFAULT 'FOREST',"
+ " `rain` INT(1) DEFAULT 0," + " `custom_time` TINYINT(1) DEFAULT '0',"
+ " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0',"
+ " `alias` VARCHAR(50) DEFAULT NULL," + " `flags` VARCHAR(512) DEFAULT NULL,"
+ " `alias` VARCHAR(50) DEFAULT NULL,"
+ " `merged` INT(11) DEFAULT NULL,"
+ " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT',"
+ " PRIMARY KEY (`cluster_id`)" + ')');
@ -1237,6 +1240,11 @@ import java.util.concurrent.atomic.AtomicInteger;
+ " `meta_id` INTEGER PRIMARY KEY AUTOINCREMENT,"
+ " `uuid` VARCHAR(40) NOT NULL," + " `key` VARCHAR(32) NOT NULL,"
+ " `value` blob NOT NULL" + ')');
stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot_flags`("
+ "`id` INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "`plot_id` INTEGER NOT NULL," + " `flag` VARCHAR(256)," + " `value` VARCHAR(512),"
+ "FOREIGN KEY (plot_id) REFERENCES `" + this.prefix + "plot` (id) ON DELETE CASCADE, "
+ "UNIQUE (plot_id, flag))");
}
stmt.executeBatch();
stmt.clearBatch();
@ -1590,6 +1598,82 @@ import java.util.concurrent.atomic.AtomicInteger;
}, null);
}
@Override public boolean convertFlags() {
final Map<Integer, Map<String, String>> flagMap = new HashMap<>();
try (Statement statement = this.connection.createStatement()) {
try (ResultSet resultSet = statement
.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) {
while (resultSet.next()) {
final int id = resultSet.getInt("plot_plot_id");
final String plotFlags = resultSet.getString("flags");
if (plotFlags == null || plotFlags.isEmpty()) {
continue;
}
flagMap.put(id, new HashMap<>());
for (String element : plotFlags.split(",")) {
if (element.contains(":")) {
String[] split = element.split(":"); // splits flag:value
try {
String flag_str =
split[1].replaceAll("¯", ":").replaceAll("\u00B4", ",");
/*PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(split[0]);
if (flag == null) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Flag not found and therefore ignored: " + split[0]);
continue;
}*/
flagMap.get(id).put(split[0], flag_str);
} catch (Exception e) {
e.printStackTrace();
}
} /*else {
element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
if (StringMan
.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(element);
if (flag == null) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Flag not found and therefore ignored: " + element);
}
} else {
PlotSquared.log(Captions.PREFIX.getTranslated() + "INVALID FLAG: " + element);
}
}*/
}
}
}
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to load old flag values:");
e.printStackTrace();
return false;
}
PlotSquared.log(Captions.PREFIX.getTranslated() + "Loaded " + flagMap.size() + " plot flag collections...");
PlotSquared.log(Captions.PREFIX.getTranslated() + "Attempting to store these flags in the new table...");
//
try (final PreparedStatement preparedStatement =
this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) {
for (final Map.Entry<Integer, Map<String, String>> plotFlagEntry : flagMap.entrySet()) {
for (final Map.Entry<String, String> flagEntry : plotFlagEntry.getValue().entrySet()) {
preparedStatement.setInt(1, plotFlagEntry.getKey());
preparedStatement.setString(2, flagEntry.getKey());
preparedStatement.setString(3, flagEntry.getValue());
preparedStatement.addBatch();
}
try {
preparedStatement.executeBatch();
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store flag values for plot with entry ID: " + plotFlagEntry.getKey());
e.printStackTrace();
continue;
}
PlotSquared.debug(Captions.PREFIX.getTranslated() + "- Finished converting flags for plot with entry ID: " + plotFlagEntry.getKey());
}
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store flag values:");
e.printStackTrace();
return false;
}
return true;
}
/**
* Load all plots, helpers, denied, trusted, and every setting from DB into a {@link HashMap}.
*/
@ -1817,6 +1901,50 @@ import java.util.concurrent.atomic.AtomicInteger;
deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id");
}
try (final ResultSet resultSet = statement.executeQuery("SELECT * FROM `" + this.prefix + "plot_flags`")) {
final ArrayList<Integer> toDelete = new ArrayList<>();
final Map<Plot, Collection<PlotFlag<?,?>>> invalidFlags = new HashMap<>();
while (resultSet.next()) {
id = resultSet.getInt("plot_id");
final String flag = resultSet.getString("flag");
final String value = resultSet.getString("value");
final Plot plot = plots.get(id);
if (plot != null) {
final PlotFlag<?,?> plotFlag = GlobalFlagContainer.getInstance().getFlagFromString(flag);
if (plotFlag == null) {
plot.getFlagContainer().addUnknownFlag(flag, value);
} else {
try {
plot.getFlagContainer().addFlag(plotFlag.parse(value));
} catch (final FlagParseException e) {
PlotSquared.debug("Plot with ID " + id + " has an invalid value:");
PlotSquared.debug(Captions.FLAG_PARSE_ERROR.getTranslated().replace("%flag_name%", plotFlag.getName())
.replace("%flag_value%", e.getValue()).replace("%error%", e.getErrorMessage()));
if (!invalidFlags.containsKey(plot)) {
invalidFlags.put(plot, new ArrayList<>());
}
invalidFlags.get(plot).add(plotFlag);
}
}
} else if (Settings.Enabled_Components.DATABASE_PURGER) {
toDelete.add(id);
} else {
PlotSquared.debug("&cPlot " + id
+ " in `plot_flags` does not exist. Create this plot or set `database-purger: true` in the settings.yml.");
}
}
if (Settings.Enabled_Components.DATABASE_PURGER) {
for (final Map.Entry<Plot, Collection<PlotFlag<?,?>>> plotFlagEntry : invalidFlags.entrySet()) {
for (final PlotFlag<?,?> flag : plotFlagEntry.getValue()) {
PlotSquared.debug("&cPlot \"" + plotFlagEntry.getKey() + "\""
+ " had an invalid flag (" + flag.getName() + "). A fix has been attempted.");
removeFlag(plotFlagEntry.getKey(), flag);
}
}
}
deleteRows(toDelete, this.prefix + "plot_flags", "plot_id");
}
try (ResultSet resultSet = statement
.executeQuery("SELECT * FROM `" + this.prefix + "plot_settings`")) {
ArrayList<Integer> toDelete = new ArrayList<>();
@ -1848,46 +1976,6 @@ import java.util.concurrent.atomic.AtomicInteger;
merged[3 - i] = (m & 1 << i) != 0;
}
plot.getSettings().setMerged(merged);
String[] flags_string;
String myflags = resultSet.getString("flags");
if (myflags == null || myflags.isEmpty()) {
flags_string = new String[] {};
} else {
flags_string = myflags.split(",");
}
HashMap<Flag<?>, Object> flags = new HashMap<>();
boolean exception = false;
for (String element : flags_string) {
if (element.contains(":")) {
String[] split = element.split(":");
try {
String flag_str =
split[1].replaceAll("¯", ":").replaceAll("\u00B4", ",");
Flag<?> flag = FlagManager.getOrCreateFlag(split[0]);
flags.put(flag, flag.parseValue(flag_str));
} catch (Exception e) {
e.printStackTrace();
exception = true;
}
} else {
element =
element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
if (StringMan
.isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) {
Flag flag = FlagManager.getOrCreateFlag(element);
flags.put(flag, flag.parseValue(""));
} else {
PlotSquared.debug("INVALID FLAG: " + element);
}
}
}
if (exception) {
PlotSquared.debug("&cPlot #" + id + "(" + plot + ") | " + plot
+ " had an invalid flag. A fix has been attempted.");
PlotSquared.debug("&c" + myflags);
this.setFlags(plot, flags);
}
plot.getSettings().flags = flags;
} else if (Settings.Enabled_Components.DATABASE_PURGER) {
toDelete.add(id);
} else {
@ -1991,18 +2079,39 @@ import java.util.concurrent.atomic.AtomicInteger;
addPlotTask(newPlot, null);
}
@Override public void setFlags(final Plot plot, HashMap<Flag<?>, Object> flags) {
final String flag_string = FlagManager.toString(flags);
addPlotTask(plot, new UniqueStatement("setFlags") {
@Override public void setFlag(final Plot plot, final PlotFlag<?, ?> flag) {
addPlotTask(plot, new UniqueStatement("setFlag") {
@Override public void set(PreparedStatement statement) throws SQLException {
statement.setString(1, flag_string);
statement.setInt(2, getId(plot));
statement.setInt(1, getId(plot));
statement.setString(2, flag.getName());
statement.setString(3, flag.toString());
statement.setString(4, flag.toString());
}
@Override public PreparedStatement get() throws SQLException {
return SQLManager.this.connection.prepareStatement(
"UPDATE `" + SQLManager.this.prefix
+ "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?");
final String statement;
if (SQLManager.this.mySQL) {
statement = "INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?) "
+ "ON DUPLICATE KEY UPDATE `value` = ?";
} else {
statement = "INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?) "
+ "ON CONFLICT(`plot_id`,`flag`) DO UPDATE SET `value` = ?";
}
return SQLManager.this.connection.prepareStatement(statement);
}
});
}
@Override public void removeFlag(final Plot plot, final PlotFlag<?, ?> flag) {
addPlotTask(plot, new UniqueStatement("removeFlag") {
@Override public void set(PreparedStatement statement) throws SQLException {
statement.setInt(1, getId(plot));
statement.setString(2, flag.getName());
}
@Override public PreparedStatement get() throws SQLException {
return SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix
+ "plot_flags` WHERE `plot_id` = ? AND `flag` = ?");
}
});
}
@ -2966,14 +3075,15 @@ import java.util.concurrent.atomic.AtomicInteger;
PlotSquared.debug(" - Correcting merge for: " + plot);
setMerged(dataPlot, plot.getMerged());
}
HashMap<Flag<?>, Object> pf = plot.getFlags();
HashMap<Flag<?>, Object> df = dataPlot.getFlags();
Set<PlotFlag<?, ?>> pf = plot.getFlags();
Set<PlotFlag<?, ?>> df = dataPlot.getFlags();
if (!pf.isEmpty() && !df.isEmpty()) {
if (pf.size() != df.size() || !StringMan
.isEqual(StringMan.joinOrdered(pf.values(), ","),
StringMan.joinOrdered(df.values(), ","))) {
.isEqual(StringMan.joinOrdered(pf, ","),
StringMan.joinOrdered(df, ","))) {
PlotSquared.debug(" - Correcting flags for: " + plot);
setFlags(plot, pf);
// setFlags(plot, pf);
// TODO: Re-implement
}
}
}
@ -3104,7 +3214,6 @@ import java.util.concurrent.atomic.AtomicInteger;
public abstract void set(PreparedStatement statement) throws SQLException;
}
private class UUIDPair {
public final int id;
@ -3117,12 +3226,12 @@ import java.util.concurrent.atomic.AtomicInteger;
}
private class SettingsPair {
private static class LegacySettings {
public final int id;
public final PlotSettings settings;
public SettingsPair(int id, PlotSettings settings) {
public LegacySettings(int id, PlotSettings settings) {
this.id = id;
this.settings = settings;
}

View File

@ -1,36 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.flag;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
public class BlockStateListFlag extends ListFlag<Set<BlockType>> {
public BlockStateListFlag(String name) {
super(Captions.FLAG_CATEGORY_BLOCK_LIST, name);
}
@Override public String valueToString(Object value) {
return StringMan.join((Set<BlockType>) value, ",");
}
@Override public Set<BlockType> parseValue(final String value) {
return Arrays.stream(BlockUtil.parse(value)).filter(Objects::nonNull).map(BlockState::getBlockType).collect(Collectors.toSet());
}
@Override public String getValueDescription() {
return Captions.FLAG_ERROR_PLOTBLOCKLIST.getTranslated();
}
public boolean contains(Plot plot, BlockState value) {
return contains(plot, value.getBlockType());
}
}

View File

@ -1,46 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.flag;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
public class BooleanFlag extends Flag<Boolean> {
public BooleanFlag(String name) {
super(Captions.FLAG_CATEGORY_BOOLEAN, name);
}
@Override public String valueToString(Object value) {
return value + "";
}
@Override public Boolean parseValue(String value) {
switch (value.toLowerCase()) {
case "1":
case "yes":
case "allow":
case "true":
return true;
case "0":
case "no":
case "deny":
case "false":
return false;
default:
return null;
}
}
@Override public String getValueDescription() {
return Captions.FLAG_ERROR_BOOLEAN.getTranslated();
}
public boolean isTrue(Plot plot) {
Boolean value = FlagManager.getPlotFlagRaw(plot, this);
return Boolean.TRUE == value;
}
public boolean isFalse(Plot plot) {
Boolean value = FlagManager.getPlotFlagRaw(plot, this);
return Boolean.FALSE == value;
}
}

View File

@ -1,27 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.flag;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
public class DoubleFlag extends Flag<Double> {
public DoubleFlag(String name) {
super(Captions.FLAG_CATEGORY_DECIMAL, name);
}
@Override public String valueToString(Object value) {
return value.toString();
}
@Override public Double parseValue(String value) {
try {
return Double.parseDouble(value);
} catch (NumberFormatException ignored) {
return null;
}
}
@Override public String getValueDescription() {
return Captions.FLAG_ERROR_BOOLEAN.getTranslated();
}
}

View File

@ -1,33 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.flag;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import java.util.Arrays;
import java.util.HashSet;
public class EnumFlag extends Flag<String> {
private final HashSet<String> values;
public EnumFlag(String name, String... values) {
super(Captions.FLAG_CATEGORY_ENUM, name);
this.values = new HashSet<>(Arrays.asList(values));
}
@Override public String valueToString(Object value) {
return value.toString();
}
@Override public String parseValue(String value) {
value = value.toLowerCase();
if (values.contains(value)) {
return value;
}
return null;
}
@Override public String getValueDescription() {
return Captions.FLAG_ERROR_ENUM.getTranslated() + StringMan.getString(values);
}
}

View File

@ -1,75 +0,0 @@
package com.github.intellectualsites.plotsquared.plot.flag;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
import lombok.Getter;
public abstract class Flag<V> implements StringComparison.StringComparable {
@Getter private final Captions typeCaption;
private final String name;
private boolean reserved = false;
public Flag(Captions typeCaption, String name) {
this.typeCaption = typeCaption;
this.name = name;
}
/**
* Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to
* register it with PlotSquared.
*
* @param name the flag name
*/
public Flag(String name) {
this(null, name);
}
public Flag<V> reserve() {
this.reserved = true;
return this;
}
public boolean isReserved() {
return this.reserved;
}
public void unreserve() {
this.reserved = false;
}
public void register() {
Flags.registerFlag(this);
}
public abstract String valueToString(Object value);
@Override public final String toString() {
return "Flag { name='" + getName() + "'}";
}
public abstract V parseValue(String value);
public abstract String getValueDescription();
public final String getName() {
return this.name;
}
public boolean isSet(Plot plot) {
return FlagManager.getPlotFlagRaw(plot, this) != null;
}
@Override public String getComparableString() {
return getName();
}
public String getCategoryCaption() {
return this.typeCaption == null ?
getClass().getSimpleName() :
this.typeCaption.getTranslated();
}
}

Some files were not shown because too many files have changed in this diff Show More