diff --git a/.gitignore b/.gitignore index 05139ba480..e36433205f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,6 @@ out run /dependency-reduced-pom.xml -*-private.sh \ No newline at end of file +*-private.sh +.nb-gradle +.nb-gradle-properties diff --git a/build.gradle b/build.gradle index 1e5ef96344..1f917d7cdf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ println """ ******************************************* - You are building WorldEdit! + You are building WorldEdit! If you encounter trouble: 1) Read COMPILING.md if you haven't yet @@ -48,18 +48,18 @@ if (!project.hasProperty("gitCommitHash")) { subprojects { apply plugin: 'java' apply plugin: 'maven' - apply plugin: 'checkstyle' + //apply plugin: 'checkstyle' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.jfrog.artifactory-upload' group = 'com.sk89q.worldedit' - version = '6.0.2-SNAPSHOT' + version = '6.0.2-TF' ext.internalVersion = version + ";" + gitCommitHash sourceCompatibility = 1.6 targetCompatibility = 1.6 - checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml") + //checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml") repositories { mavenCentral() @@ -91,8 +91,8 @@ subprojects { archives javadocJar } - build.dependsOn(checkstyleMain) - build.dependsOn(checkstyleTest) + //build.dependsOn(checkstyleMain) + //build.dependsOn(checkstyleTest) build.dependsOn(sourcesJar) build.dependsOn(javadocJar) @@ -116,7 +116,7 @@ subprojects { username = "${artifactory_user}" password = "${artifactory_password}" maven = true - + } } diff --git a/settings.gradle b/settings.gradle index 2713594820..8de797141c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,3 @@ rootProject.name = 'worldedit' -include 'worldedit-core', 'worldedit-bukkit', 'worldedit-forge' \ No newline at end of file +include 'worldedit-core', 'worldedit-bukkit' \ No newline at end of file diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index 66ec06d399..49bea03a69 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -11,6 +11,8 @@ dependencies { compile 'com.thoughtworks.paranamer:paranamer:2.6' compile 'com.google.code.gson:gson:2.2.4' compile 'com.sk89q.lib:jlibnoise:1.0.0' + compile 'org.sk89q.bukkit:bukkit-classloader-check:1.7.9-R0.2' + compile 'org.bukkit:bukkit:1.7.9-R0.2' //compile 'net.sf.trove4j:trove4j:3.0.3' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 5cbfea2eb7..abb15438da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jchronic.Chronic; import com.sk89q.jchronic.Options; import com.sk89q.jchronic.utils.Span; @@ -44,16 +45,13 @@ import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.snapshot.Snapshot; - -import javax.annotation.Nullable; import java.util.Calendar; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.TimeZone; import java.util.concurrent.atomic.AtomicBoolean; - -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * Stores session information. @@ -703,6 +701,10 @@ public void dispatchCUIEvent(Actor actor, CUIEvent event) { if (hasCUISupport) { actor.dispatchCUIEvent(event); } + + if (actor instanceof com.sk89q.worldedit.entity.Player) { + me.StevenLawson.worldedit.WorldEditHandler.selectionChanged((com.sk89q.worldedit.entity.Player) actor); + } } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java index 4d8aa6f8f3..2d6f20d9d4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java @@ -19,17 +19,21 @@ package com.sk89q.worldedit.command; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; -import com.sk89q.worldedit.*; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.util.command.parametric.Optional; - -import static com.google.common.base.Preconditions.checkNotNull; +import me.StevenLawson.worldedit.WorldEditHandler; /** * General WorldEdit commands. @@ -53,11 +57,11 @@ public GeneralCommands(WorldEdit worldEdit) { usage = "", desc = "Modify block change limit", min = 1, - max = 1 + max = 2 ) @CommandPermissions("worldedit.limit") public void limit(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - + LocalConfiguration config = worldEdit.getConfiguration(); boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted"); @@ -69,10 +73,27 @@ public void limit(Player player, LocalSession session, EditSession editSession, } } - session.setBlockChangeLimit(limit); + // TFM Start + final String targetName = (args.argsLength() == 2 ? args.getString(1) : null); + final LocalSession targetSession = (targetName == null ? + WorldEdit.getInstance().getSessionManager().get(player) : + WorldEdit.getInstance().getSessionManager().findByName(targetName)); + + if (targetSession == null) { + player.printError("Could not resolve player session for player: " + targetName); + return; + } + + limit = WorldEditHandler.limitChanged(player, limit, targetName); + if (limit < -1) { + return; + } + // TFM End + + targetSession.setBlockChangeLimit(limit); if (limit != -1) { - player.print("Block change limit set to " + limit + ". (Use //limit -1 to go back to the default.)"); + player.print("Block change limit set to " + limit + ". (Use //limit 2500 to go back to the default.)"); } else { player.print("Block change limit set to " + limit + "."); } @@ -156,7 +177,7 @@ public void togglePlace(Player player, LocalSession session, EditSession editSes max = 1 ) public void searchItem(Actor actor, CommandContext args) throws WorldEditException { - + String query = args.getString(0).trim().toLowerCase(); boolean blocksOnly = args.hasFlag('b'); boolean itemsOnly = args.hasFlag('i'); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java index beb9bc5d7b..e9dfea6ce0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java @@ -19,8 +19,18 @@ package com.sk89q.worldedit.extension.factory; -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.*; +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.NotABlockException; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockType; +import com.sk89q.worldedit.blocks.ClothColor; +import com.sk89q.worldedit.blocks.MobSpawnerBlock; +import com.sk89q.worldedit.blocks.NoteBlock; +import com.sk89q.worldedit.blocks.SignBlock; +import com.sk89q.worldedit.blocks.SkullBlock; import com.sk89q.worldedit.blocks.metadata.MobType; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.DisallowedUsageException; @@ -30,6 +40,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.world.World; +import me.StevenLawson.worldedit.WorldEditHandler; /** * Parses block input strings. @@ -245,6 +256,14 @@ public BaseBlock parseFromInput(String input, ParserContext context) throws Inpu throw new DisallowedUsageException("You are not allowed to use '" + input + "'"); } + // TFM start + if (actor instanceof Player + && worldEdit.getConfiguration().disallowedBlocks.contains(blockId) + && !WorldEditHandler.isSuperAdmin((Player) actor)) { + throw new DisallowedUsageException("You are not allowed to use '" + input + "'"); + } + // TFM end + if (blockType == null) { return new BaseBlock(blockId, data); } diff --git a/worldedit-core/src/main/java/me/StevenLawson/worldedit/LimitChangedEvent.java b/worldedit-core/src/main/java/me/StevenLawson/worldedit/LimitChangedEvent.java new file mode 100644 index 0000000000..eca5d1d9be --- /dev/null +++ b/worldedit-core/src/main/java/me/StevenLawson/worldedit/LimitChangedEvent.java @@ -0,0 +1,51 @@ +package me.StevenLawson.worldedit; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class LimitChangedEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled = false; + private final Player target; + private int limit; + + public LimitChangedEvent(Player from, Player target, int limit) { + super(from); + this.target = target; + this.limit = limit; + } + + public Player getTarget() { + return target; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean bln) { + this.cancelled = bln; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/worldedit-core/src/main/java/me/StevenLawson/worldedit/SelectionChangedEvent.java b/worldedit-core/src/main/java/me/StevenLawson/worldedit/SelectionChangedEvent.java new file mode 100644 index 0000000000..1df4be2e04 --- /dev/null +++ b/worldedit-core/src/main/java/me/StevenLawson/worldedit/SelectionChangedEvent.java @@ -0,0 +1,57 @@ +package me.StevenLawson.worldedit; + +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.util.Vector; + +public class SelectionChangedEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled = false; + private final World world; + private final Vector minVector; + private final Vector maxVector; + + + public SelectionChangedEvent(Player player, World world, Vector minVector, Vector maxVector) { + super(player); + + this.world = world; + this.minVector = minVector; + this.maxVector = maxVector; + } + + public World getWorld() { + return world; + } + + public Vector getMaxVector() { + return maxVector; + } + + public Vector getMinVector() { + return minVector; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean bln) { + this.cancelled = bln; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/worldedit-core/src/main/java/me/StevenLawson/worldedit/WorldEditHandler.java b/worldedit-core/src/main/java/me/StevenLawson/worldedit/WorldEditHandler.java new file mode 100644 index 0000000000..cad51f7baf --- /dev/null +++ b/worldedit-core/src/main/java/me/StevenLawson/worldedit/WorldEditHandler.java @@ -0,0 +1,169 @@ +package me.StevenLawson.worldedit; + +import com.google.common.base.Function; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.regions.Region; +import java.util.logging.Logger; +import javax.annotation.Nullable; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.util.Vector; + +public class WorldEditHandler { + + public static final boolean DEBUG = true; + public static final Logger LOGGER = Bukkit.getPluginManager().getPlugin("WorldEdit").getLogger(); + private static Function superAdminProvider; + + public static void selectionChanged(com.sk89q.worldedit.entity.Player wePlayer) { + final Player player = getPlayer(wePlayer); + if (player == null) { + return; + } + + final Region region; + + try { + region = WorldEdit.getInstance().getSessionManager().get(wePlayer).getSelection(wePlayer.getWorld()); + } catch (IncompleteRegionException ex) { + return; + } + + final SelectionChangedEvent event = new SelectionChangedEvent( + player, + player.getWorld(), + new Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ()), + new Vector(region.getMaximumPoint().getX(), region.getMaximumPoint().getY(), region.getMaximumPoint().getZ())); + + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + WorldEdit.getInstance().getSessionManager().get(wePlayer).getRegionSelector(wePlayer.getWorld()).clear(); + } + } + + public static int limitChanged(com.sk89q.worldedit.entity.Player wePlayer, int limit, @Nullable String targetName) { + final int failCondition = -10; + final int defaultCondition = (limit >= 1 && limit <= 10000 ? limit : failCondition); + final Player player = getPlayer(wePlayer); + if (player == null) { + return defaultCondition; + } + + final Player target; + if (targetName == null) { + target = player; + } else { + target = getPlayer(targetName); + } + + if (target == null) { + return defaultCondition; + } + + final LimitChangedEvent event = new LimitChangedEvent(player, target, limit); + Bukkit.getPluginManager().callEvent(event); + + return event.isCancelled() ? failCondition : event.getLimit(); + } + + @SuppressWarnings("unchecked") + public static boolean isSuperAdmin(com.sk89q.worldedit.entity.Player wePlayer) { + final Player player = getPlayer(wePlayer); + if (player == null) { + return false; + } + + if (superAdminProvider == null) { + final Plugin tfm = getTFM(); + if (tfm == null) { + return false; + } + + Object provider = null; + for (RegisteredServiceProvider serv : Bukkit.getServicesManager().getRegistrations(tfm)) { + if (Function.class.isAssignableFrom(serv.getService())) { + provider = serv.getProvider(); + } + } + + if (provider == null) { + warning("Could not obtain SuperAdmin service provider!"); + return false; + } + + superAdminProvider = (Function) provider; + } + + return superAdminProvider.apply(player); + } + + public static Player getPlayer(com.sk89q.worldedit.entity.Player wePlayer) { + final Player player = Bukkit.getPlayer(wePlayer.getUniqueId()); + + if (player == null) { + debug("Could not resolve Bukkit player: " + wePlayer.getName()); + return null; + } + + return player; + } + + public static Player getPlayer(String match) { + match = match.toLowerCase(); + + Player found = null; + int delta = Integer.MAX_VALUE; + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.getName().toLowerCase().startsWith(match)) { + int curDelta = player.getName().length() - match.length(); + if (curDelta < delta) { + found = player; + delta = curDelta; + } + if (curDelta == 0) { + break; + } + } + } + + for (Player player : Bukkit.getOnlinePlayers()) { + if (player.getName().toLowerCase().contains(match)) { + return player; + } + } + return found; + } + + public static World getWorld(com.sk89q.worldedit.world.World world) { + return Bukkit.getWorld(world.getName()); + } + + public static Plugin getTFM() { + final Plugin tfm = Bukkit.getPluginManager().getPlugin("TotalFreedomMod"); + if (tfm == null) { + LOGGER.warning("Could not resolve plugin: TotalFreedomMod"); + } + + return tfm; + } + + public static void debug(String debug) { + if (DEBUG) { + info(debug); + } + } + + public static void warning(String warning) { + LOGGER.warning(warning); + } + + public static void info(String info) { + LOGGER.info(info); + } + +}