Skip to content

Commit

Permalink
Allow placing boats on ground for MC 1.12 with protocol support plugins.
Browse files Browse the repository at this point in the history
Allowing it with protocol support plugins is added, assuming that
they'll allow 1.12 too.

Missing:
* The vehicle.envelope check must be made (more) precise, as moving on
ground is possible with a boat since 1.12, specifically on ice they can
reach high speeds. Without more close modeling, they'll be able to use
this for speeding.
  • Loading branch information
asofold committed May 28, 2017
1 parent 049a925 commit b441c1e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Expand Up @@ -27,6 +27,8 @@
import fr.neatmonster.nocheatplus.checks.access.ACheckConfig;
import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory;
import fr.neatmonster.nocheatplus.checks.access.ICheckConfig;
import fr.neatmonster.nocheatplus.compat.activation.ActivationUtil;
import fr.neatmonster.nocheatplus.components.registry.activation.Activation;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
Expand Down Expand Up @@ -102,7 +104,9 @@ public static BlockPlaceConfig getConfig(final Player player) {
public final long speedInterval;
public final ActionList speedActions;

/** General activation flag. */
public final boolean preventBoatsAnywhere;
public final boolean preventBoatsGround;

/**
* Instantiates a new block place configuration.
Expand Down Expand Up @@ -142,6 +146,9 @@ public BlockPlaceConfig(final ConfigFile config) {
speedActions = config.getOptimizedActionList(ConfPaths.BLOCKPLACE_SPEED_ACTIONS, Permissions.BLOCKPLACE_SPEED);

preventBoatsAnywhere = config.getBoolean(ConfPaths.BLOCKPLACE_PREVENTMISC_BOATSANYWHERE);
Activation activation = ActivationUtil.addMultiProtocolSupportPlugins(
new Activation().setConditionsOR().minecraftVersionGT("1.12", true));
preventBoatsGround = !activation.isAvailable();
}

/* (non-Javadoc)
Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -334,7 +335,9 @@ public void onPlayerInteract(final PlayerInteractEvent event) {
final Material type = stack.getType();
if (InventoryUtil.isBoat(type)) {
if (cc.preventBoatsAnywhere) {
checkBoatsAnywhere(player, event);
// TODO: Alter config (activation, allow on top of ground).
// TODO: Version/plugin specific alteration for 'default'.
checkBoatsAnywhere(player, event, cc);
}
}
else if (type == Material.MONSTER_EGG) {
Expand All @@ -346,24 +349,37 @@ else if (type == Material.MONSTER_EGG) {
}
}

private void checkBoatsAnywhere(final Player player, final PlayerInteractEvent event) {
private void checkBoatsAnywhere(final Player player, final PlayerInteractEvent event,
final BlockPlaceConfig cc) {
// Check boats-anywhere.
final org.bukkit.block.Block block = event.getClickedBlock();
final Block block = event.getClickedBlock();
final Material mat = block.getType();

// TODO: allow lava ?
if (BlockProperties.isWater(mat)) {
return;
}

final org.bukkit.block.Block relBlock = block.getRelative(event.getBlockFace());
// TODO: Shouldn't this be the opposite face?
final BlockFace blockFace = event.getBlockFace();
final Block relBlock = block.getRelative(blockFace);
final Material relMat = relBlock.getType();

// TODO: Placing inside of water, but not "against" ?
if (BlockProperties.isWater(relMat)) {
return;
}

// Allow placing boats on ground since 1.12.
/*
* TODO: Prevent, if the placed boat would collide with any blocks or
* entities - alternatively perform post-mortem entity destruction.
*/
if (!cc.preventBoatsGround && blockFace == BlockFace.UP && BlockProperties.isGround(mat)
&& BlockProperties.isPassable(block.getRelative(BlockFace.UP).getType())) {
return;
}

// TODO: Add a check type for exemption?
if (!player.hasPermission(Permissions.BLOCKPLACE_BOATSANYWHERE)) {
final Result previousUseBlock = event.useInteractedBlock();
Expand Down

3 comments on commit b441c1e

@RoboMWM
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may or may not be aware already, but these discoveries you've made in "Missing" have in fact been in the game since 1.9 (with the "new" boats). Technically, you could move on ground a boat pre-1.9, albeit extremely slowly.

@0-x-2-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you went on ice it was really fast

@asofold
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really fast on ice now :).

It's been possible to placve boats on ground at least since CB 1.4.5-R1.0, checked it myself - thus i reverted this change. It was a too fast shot trying to "do something about it".

Please sign in to comment.