Added plot disable-physics flag

This commit is contained in:
boy0001 2015-06-06 00:08:16 +10:00
parent 93a40653c0
commit e5170fdbd4
15 changed files with 94 additions and 56 deletions

View File

@ -2,14 +2,9 @@ package com.intellectualcrafters.plot;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@ -20,13 +15,11 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.commands.Add;
import com.intellectualcrafters.plot.commands.Auto;
import com.intellectualcrafters.plot.commands.BukkitCommand;
import com.intellectualcrafters.plot.commands.Buy;
import com.intellectualcrafters.plot.commands.Chat;
import com.intellectualcrafters.plot.commands.Claim;
import com.intellectualcrafters.plot.commands.Clear;

View File

@ -3,12 +3,9 @@ package com.intellectualcrafters.plot;
import java.io.File;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.listeners.APlotListener;
import com.intellectualcrafters.plot.object.PlotPlayer;

View File

@ -25,12 +25,8 @@ import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.commands.Cluster;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.Settings;
@ -718,6 +714,9 @@ public class PlotSquared {
for (final String flag : intFlags) {
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue()));
}
if (Settings.PHYSICS_LISTENER) {
FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
}
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue()));
@ -802,6 +801,7 @@ public class PlotSquared {
// Protection
options.put("protection.tnt-listener.enabled", Settings.TNT_LISTENER);
options.put("protection.piston.falling-blocks", Settings.PISTON_FALLING_BLOCK_CHECK);
options.put("protection.physics-listener.enabled", Settings.PHYSICS_LISTENER);
// Clusters
options.put("clusters.enabled", Settings.ENABLE_CLUSTERS);
@ -880,6 +880,7 @@ public class PlotSquared {
// Protection
Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled");
Settings.PISTON_FALLING_BLOCK_CHECK = config.getBoolean("protection.piston.falling-blocks");
Settings.PHYSICS_LISTENER = config.getBoolean("protection.physics-listener.enabled");
// Clusters
Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled");

View File

@ -20,8 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import net.milkbowl.vault.economy.Economy;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;

View File

@ -1,8 +1,6 @@
package com.intellectualcrafters.plot.commands;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.UUID;

View File

@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;

View File

@ -22,13 +22,13 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import com.intellectualcrafters.plot.config.C;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;

View File

@ -21,13 +21,8 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class Toggle extends SubCommand {
public Toggle() {

View File

@ -61,6 +61,10 @@ public class Settings {
* Check for falling blocks when pistons extend?
*/
public static boolean PISTON_FALLING_BLOCK_CHECK = true;
/**
* Physics listener
*/
public static boolean PHYSICS_LISTENER = false;
/**
* Max auto claiming size
*/

View File

@ -8,7 +8,6 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetBlockQueue;

View File

@ -11,6 +11,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
@ -18,6 +19,7 @@ import org.bukkit.entity.Animals;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Monster;
@ -100,7 +102,6 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.sk89q.worldedit.function.EntityFunction;
/**
* Player Events involving plots
@ -161,6 +162,30 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
event.setNewCurrent(0);
}
public static void sendBlockChange(final org.bukkit.Location bloc, final Material type, final byte data) {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
String world = bloc.getWorld().getName();
int x = bloc.getBlockX();
int z = bloc.getBlockZ();
int distance = Bukkit.getViewDistance() * 16;
for (PlotPlayer player : UUIDHandler.players.values()) {
Location loc = player.getLocation();
if (loc.getWorld().equals(world)) {
if (16 * (Math.abs(loc.getX() - x)/16) > distance) {
continue;
}
if (16 * (Math.abs(loc.getZ() - z)/16) > distance) {
continue;
}
((BukkitPlayer) player).player.sendBlockChange(bloc, type, data);
}
}
}
}, 3);
}
@EventHandler
public void onPhysicsEvent(BlockPhysicsEvent event) {
Block block = event.getBlock();
@ -183,6 +208,16 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return;
}
event.setCancelled(true);
return;
}
}
if (Settings.PHYSICS_LISTENER && block.getType().hasGravity()) {
Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return;
}
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
event.setCancelled(true);
}
}
}
@ -644,6 +679,12 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true);
}
else if (Settings.PHYSICS_LISTENER) {
Plot plot = MainUtil.getPlot(loc);
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
e.setCancelled(true);
}
}
}
}
@ -848,7 +889,30 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (checkEntity(entity, plot)) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onEntityFall(EntityChangeBlockEvent event) {
if (!Settings.PHYSICS_LISTENER) {
return;
}
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
return;
}
Block block = event.getBlock();
World world = block.getWorld();
String worldname = world.getName();
if (!PlotSquared.isPlotWorld(worldname)) {
return;
}
Location loc = BukkitUtil.getLocation(block.getLocation());
Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return;
}
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
event.setCancelled(true);
}
}
public boolean checkEntity(Entity entity, Plot plot) {
@ -1469,7 +1533,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled=true)
public void BlockCreate(final BlockPlaceEvent event) {
final Player player = event.getPlayer();
final String world = player.getWorld().getName();
@ -1477,32 +1541,31 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return;
}
final PlotPlayer pp = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(pp, "plots.admin")) {
return;
}
final Location loc = BukkitUtil.getLocation(event.getBlock().getLocation());
final Plot plot = MainUtil.getPlot(loc);
if (plot != null) {
if (!plot.hasOwner()) {
if (Permissions.hasPermission(pp, "plots.admin.build.unowned")) {
if (!Permissions.hasPermission(pp, "plots.admin.build.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.unowned");
event.setCancelled(true);
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.unowned");
event.setCancelled(true);
return;
}
if (!plot.isAdded(pp.getUUID())) {
else if (!plot.isAdded(pp.getUUID())) {
final Flag place = FlagManager.getPlotFlag(plot, "place");
final Block block = event.getBlock();
if ((place != null) && ((HashSet<PlotBlock>) place.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) {
return;
}
if (!Permissions.hasPermission(pp, "plots.admin.build.other")) {
if (((place == null) || !((HashSet<PlotBlock>) place.getValue()).contains(new PlotBlock((short) block.getTypeId(), block.getData()))) && !Permissions.hasPermission(pp, "plots.admin.build.other")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.build.other");
event.setCancelled(true);
return;
}
}
if (Settings.PHYSICS_LISTENER) {
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
Block block = event.getBlockPlaced();
sendBlockChange(block.getLocation(), block.getType(), block.getData());
}
}
return;
}
else if (!Permissions.hasPermission(pp, "plots.admin.build.road")) {

View File

@ -3,11 +3,8 @@ package com.intellectualcrafters.plot.util;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.util;
import java.io.File;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PlotSquared;
@ -10,7 +11,6 @@ import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.regions.CuboidRegion;
public class WorldEditSchematic {
public void saveSchematic(String file, final String world, final PlotId id) {

View File

@ -1,11 +1,11 @@
package com.intellectualcrafters.plot.util.bukkit;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;

View File

@ -25,18 +25,12 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil;
/**