Skip to content

Commit

Permalink
Some further work on Spigot 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Jul 22, 2018
1 parent 227cebb commit 8d75bad
Show file tree
Hide file tree
Showing 47 changed files with 324 additions and 432 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -62,7 +62,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13-pre7-R0.1-SNAPSHOT</version>
<version>1.13-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
Expand All @@ -77,7 +77,7 @@
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>6.2</version>
<version>7.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
Expand Down
108 changes: 60 additions & 48 deletions src/main/java/com/sk89q/craftbook/bukkit/MechanicListenerAdapter.java
Expand Up @@ -16,6 +16,7 @@

package com.sk89q.craftbook.bukkit;

import com.sk89q.craftbook.bukkit.util.CraftBookBukkitUtil;
import com.sk89q.craftbook.mechanics.minecart.blocks.CartBlockMechanism;
import com.sk89q.craftbook.mechanics.minecart.blocks.CartMechanismBlocks;
import com.sk89q.craftbook.mechanics.minecart.events.CartBlockEnterEvent;
Expand All @@ -28,9 +29,6 @@
import com.sk89q.craftbook.util.events.SignClickEvent;
import com.sk89q.craftbook.util.events.SourcedBlockRedstoneEvent;
import com.sk89q.craftbook.util.exceptions.InvalidMechanismException;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -77,7 +75,7 @@ public void onPlayerInteract(final PlayerInteractEvent event) {
Action action = null;
if(event.getAction() == Action.RIGHT_CLICK_AIR) {
try {
block = event.getPlayer().getTargetBlock((Set<Material>)null, 5);
block = event.getPlayer().getTargetBlock(null, 5);
if(block != null && block.getType() != Material.AIR)
action = Action.RIGHT_CLICK_BLOCK;
else
Expand Down Expand Up @@ -130,11 +128,11 @@ public void onBlockPlace(BlockPlaceEvent event) {

private static void checkBlockChange(Player player, Block block, boolean build) {
switch(block.getType()) {

case REDSTONE_TORCH_ON:
case DIODE_BLOCK_ON:
case REDSTONE_TORCH:
case REDSTONE_WALL_TORCH:
case REPEATER:
case REDSTONE_BLOCK:
case REDSTONE_COMPARATOR_ON:
case COMPARATOR:
if(CraftBookPlugin.inst().getConfiguration().pedanticBlockChecks && !ProtectionUtil.canBuild(player, block.getLocation(), build))
break;
handleRedstoneForBlock(block, build ? 0 : 15, build ? 15 : 0);
Expand All @@ -151,17 +149,27 @@ private static void checkBlockChange(Player player, Block block, boolean build)
if(((org.bukkit.material.Lever) block.getState().getData()).isPowered())
handleRedstoneForBlock(block, build ? 0 : 15, build ? 15 : 0);
break;
case WOOD_BUTTON:
case ACACIA_BUTTON:
case BIRCH_BUTTON:
case DARK_OAK_BUTTON:
case JUNGLE_BUTTON:
case OAK_BUTTON:
case SPRUCE_BUTTON:
case STONE_BUTTON:
if(CraftBookPlugin.inst().getConfiguration().pedanticBlockChecks && !ProtectionUtil.canBuild(player, block.getLocation(), build))
break;
if(((org.bukkit.material.Button) block.getState().getData()).isPowered())
handleRedstoneForBlock(block, build ? 0 : 15, build ? 15 : 0);
break;
case STONE_PLATE:
case WOOD_PLATE:
case GOLD_PLATE:
case IRON_PLATE:
case STONE_PRESSURE_PLATE:
case ACACIA_PRESSURE_PLATE:
case BIRCH_PRESSURE_PLATE:
case DARK_OAK_PRESSURE_PLATE:
case HEAVY_WEIGHTED_PRESSURE_PLATE:
case JUNGLE_PRESSURE_PLATE:
case LIGHT_WEIGHTED_PRESSURE_PLATE:
case OAK_PRESSURE_PLATE:
case SPRUCE_PRESSURE_PLATE:
case DETECTOR_RAIL:
if(CraftBookPlugin.inst().getConfiguration().pedanticBlockChecks && !ProtectionUtil.canBuild(player, block.getLocation(), build))
break;
Expand Down Expand Up @@ -203,8 +211,8 @@ private static void handleRedstoneForBlock(Block block, int oldLevel, int newLev
// yet been updated, so we're going to do this very ugly thing of
// faking the value with the new one whenever the data value of this
// block is requested -- it is quite ugly
switch(block.getTypeId()) {
case BlockID.REDSTONE_WIRE:
switch(block.getType()) {
case REDSTONE_WIRE:
if (CraftBookPlugin.inst().getConfiguration().indirectRedstone) {

// power all blocks around the redstone wire on the same y level
Expand All @@ -222,40 +230,40 @@ private static void handleRedstoneForBlock(Block block, int oldLevel, int newLev
handleDirectWireInput(x, y - 1, z, block, oldLevel, newLevel);
} else {

int above = world.getBlockTypeIdAt(x, y + 1, z);
Material above = world.getBlockAt(x, y + 1, z).getType();

int westSide = world.getBlockTypeIdAt(x, y, z + 1);
int westSideAbove = world.getBlockTypeIdAt(x, y + 1, z + 1);
int westSideBelow = world.getBlockTypeIdAt(x, y - 1, z + 1);
int eastSide = world.getBlockTypeIdAt(x, y, z - 1);
int eastSideAbove = world.getBlockTypeIdAt(x, y + 1, z - 1);
int eastSideBelow = world.getBlockTypeIdAt(x, y - 1, z - 1);
Material westSide = world.getBlockAt(x, y, z + 1).getType();
Material westSideAbove = world.getBlockAt(x, y + 1, z + 1).getType();
Material westSideBelow = world.getBlockAt(x, y - 1, z + 1).getType();
Material eastSide = world.getBlockAt(x, y, z - 1).getType();
Material eastSideAbove = world.getBlockAt(x, y + 1, z - 1).getType();
Material eastSideBelow = world.getBlockAt(x, y - 1, z - 1).getType();

int northSide = world.getBlockTypeIdAt(x - 1, y, z);
int northSideAbove = world.getBlockTypeIdAt(x - 1, y + 1, z);
int northSideBelow = world.getBlockTypeIdAt(x - 1, y - 1, z);
int southSide = world.getBlockTypeIdAt(x + 1, y, z);
int southSideAbove = world.getBlockTypeIdAt(x + 1, y + 1, z);
int southSideBelow = world.getBlockTypeIdAt(x + 1, y - 1, z);
Material northSide = world.getBlockAt(x - 1, y, z).getType();
Material northSideAbove = world.getBlockAt(x - 1, y + 1, z).getType();
Material northSideBelow = world.getBlockAt(x - 1, y - 1, z).getType();
Material southSide = world.getBlockAt(x + 1, y, z).getType();
Material southSideAbove = world.getBlockAt(x + 1, y + 1, z).getType();
Material southSideBelow = world.getBlockAt(x + 1, y - 1, z).getType();

// Make sure that the wire points to only this block
if (!BlockType.isRedstoneBlock(westSide) && !BlockType.isRedstoneBlock(eastSide)
&& (!BlockType.isRedstoneBlock(westSideAbove) || westSide == 0 || above != 0)
&& (!BlockType.isRedstoneBlock(eastSideAbove) || eastSide == 0 || above != 0)
&& (!BlockType.isRedstoneBlock(westSideBelow) || westSide != 0)
&& (!BlockType.isRedstoneBlock(eastSideBelow) || eastSide != 0)) {
if (!CraftBookBukkitUtil.isRedstoneBlock(westSide) && !CraftBookBukkitUtil.isRedstoneBlock(eastSide)
&& (!CraftBookBukkitUtil.isRedstoneBlock(westSideAbove) || westSide == Material.AIR || above != Material.AIR)
&& (!CraftBookBukkitUtil.isRedstoneBlock(eastSideAbove) || eastSide == Material.AIR || above != Material.AIR)
&& (!CraftBookBukkitUtil.isRedstoneBlock(westSideBelow) || westSide != Material.AIR)
&& (!CraftBookBukkitUtil.isRedstoneBlock(eastSideBelow) || eastSide != Material.AIR)) {
// Possible blocks north / south
handleDirectWireInput(x - 1, y, z, block, oldLevel, newLevel);
handleDirectWireInput(x + 1, y, z, block, oldLevel, newLevel);
handleDirectWireInput(x - 1, y - 1, z, block, oldLevel, newLevel);
handleDirectWireInput(x + 1, y - 1, z, block, oldLevel, newLevel);
}

if (!BlockType.isRedstoneBlock(northSide) && !BlockType.isRedstoneBlock(southSide)
&& (!BlockType.isRedstoneBlock(northSideAbove) || northSide == 0 || above != 0)
&& (!BlockType.isRedstoneBlock(southSideAbove) || southSide == 0 || above != 0)
&& (!BlockType.isRedstoneBlock(northSideBelow) || northSide != 0)
&& (!BlockType.isRedstoneBlock(southSideBelow) || southSide != 0)) {
if (!CraftBookBukkitUtil.isRedstoneBlock(northSide) && !CraftBookBukkitUtil.isRedstoneBlock(southSide)
&& (!CraftBookBukkitUtil.isRedstoneBlock(northSideAbove) || northSide == Material.AIR || above != Material.AIR)
&& (!CraftBookBukkitUtil.isRedstoneBlock(southSideAbove) || southSide == Material.AIR || above != Material.AIR)
&& (!CraftBookBukkitUtil.isRedstoneBlock(northSideBelow) || northSide != Material.AIR)
&& (!CraftBookBukkitUtil.isRedstoneBlock(southSideBelow) || southSide != Material.AIR)) {
// Possible blocks west / east
handleDirectWireInput(x, y, z - 1, block, oldLevel, newLevel);
handleDirectWireInput(x, y, z + 1, block, oldLevel, newLevel);
Expand All @@ -270,14 +278,12 @@ private static void handleRedstoneForBlock(Block block, int oldLevel, int newLev
handleDirectWireInput(x, y - 1, z, block, oldLevel, newLevel);
}
return;
case BlockID.REDSTONE_REPEATER_OFF:
case BlockID.REDSTONE_REPEATER_ON:
case BlockID.COMPARATOR_OFF:
case BlockID.COMPARATOR_ON:
case REPEATER:
case COMPARATOR:
Directional diode = (Directional) block.getState().getData();
BlockFace f = diode.getFacing();
handleDirectWireInput(x + f.getModX(), y, z + f.getModZ(), block, oldLevel, newLevel);
if(block.getRelative(f).getTypeId() != 0) {
if(block.getRelative(f).getType() != Material.AIR) {
handleDirectWireInput(x + f.getModX(), y - 1, z + f.getModZ(), block, oldLevel, newLevel);
handleDirectWireInput(x + f.getModX(), y + 1, z + f.getModZ(), block, oldLevel, newLevel);
handleDirectWireInput(x + f.getModX() + 1, y - 1, z + f.getModZ(), block, oldLevel, newLevel);
Expand All @@ -286,17 +292,23 @@ private static void handleRedstoneForBlock(Block block, int oldLevel, int newLev
handleDirectWireInput(x + f.getModX() - 1, y - 1, z + f.getModZ() - 1, block, oldLevel, newLevel);
}
return;
case BlockID.STONE_BUTTON:
case BlockID.WOODEN_BUTTON:
case BlockID.LEVER:
case ACACIA_BUTTON:
case BIRCH_BUTTON:
case DARK_OAK_BUTTON:
case JUNGLE_BUTTON:
case OAK_BUTTON:
case SPRUCE_BUTTON:
case STONE_BUTTON:
case LEVER:
Attachable button = (Attachable) block.getState().getData();
if(button != null) {
BlockFace face = button.getAttachedFace();
if(face != null)
handleDirectWireInput(x + face.getModX()*2, y + face.getModY()*2, z + face.getModZ()*2, block, oldLevel, newLevel);
}
break;
case BlockID.POWERED_RAIL:
case POWERED_RAIL:
case ACTIVATOR_RAIL:
return;
}

Expand Down Expand Up @@ -332,7 +344,7 @@ private static void handleRedstoneForBlock(Block block, int oldLevel, int newLev
private static void handleDirectWireInput(int x, int y, int z, Block sourceBlock, int oldLevel, int newLevel) {

Block block = sourceBlock.getWorld().getBlockAt(x, y, z);
if(BukkitUtil.equals(sourceBlock.getLocation(), block.getLocation())) //The same block, don't run.
if(CraftBookBukkitUtil.equals(sourceBlock.getLocation(), block.getLocation())) //The same block, don't run.
return;
final SourcedBlockRedstoneEvent event = new SourcedBlockRedstoneEvent(sourceBlock, block, oldLevel, newLevel);

Expand Down
Expand Up @@ -4,13 +4,19 @@
import com.sk89q.craftbook.CraftBookPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.util.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;

import java.util.HashSet;
import java.util.Set;

// $Id$
/*
* WorldEdit Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
Expand Down Expand Up @@ -115,4 +121,45 @@ public static org.bukkit.Location toLocation(Location teleportLocation) {
public static World toWorld(final com.sk89q.worldedit.world.World world) {
return ((BukkitWorld) world).getWorld();
}

private static final Set<Material> isRedstoneBlock = new HashSet<>();
static {
isRedstoneBlock.add(Material.POWERED_RAIL);
isRedstoneBlock.add(Material.DETECTOR_RAIL);
isRedstoneBlock.add(Material.STICKY_PISTON);
isRedstoneBlock.add(Material.PISTON);
isRedstoneBlock.add(Material.LEVER);
isRedstoneBlock.add(Material.STONE_PRESSURE_PLATE);
isRedstoneBlock.addAll(Tag.WOODEN_PRESSURE_PLATES.getValues());
isRedstoneBlock.add(Material.REDSTONE_TORCH);
isRedstoneBlock.add(Material.REDSTONE_WALL_TORCH);
isRedstoneBlock.add(Material.REDSTONE_WIRE);
isRedstoneBlock.addAll(Tag.DOORS.getValues());
isRedstoneBlock.add(Material.TNT);
isRedstoneBlock.add(Material.DISPENSER);
isRedstoneBlock.add(Material.NOTE_BLOCK);
isRedstoneBlock.add(Material.REPEATER);
isRedstoneBlock.add(Material.TRIPWIRE_HOOK);
isRedstoneBlock.add(Material.COMMAND_BLOCK);
isRedstoneBlock.addAll(Tag.BUTTONS.getValues());
isRedstoneBlock.add(Material.TRAPPED_CHEST);
isRedstoneBlock.add(Material.HEAVY_WEIGHTED_PRESSURE_PLATE);
isRedstoneBlock.add(Material.LIGHT_WEIGHTED_PRESSURE_PLATE);
isRedstoneBlock.add(Material.COMPARATOR);
isRedstoneBlock.add(Material.REDSTONE_BLOCK);
isRedstoneBlock.add(Material.HOPPER);
isRedstoneBlock.add(Material.ACTIVATOR_RAIL);
isRedstoneBlock.add(Material.DROPPER);
isRedstoneBlock.add(Material.DAYLIGHT_DETECTOR);
}

/**
* Returns true if a block uses Redstone in some way.
*
* @param id the type ID of the block
* @return true if the block uses Redstone
*/
public static boolean isRedstoneBlock(Material id) {
return isRedstoneBlock.contains(id);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/sk89q/craftbook/mechanics/BetterLeads.java
Expand Up @@ -30,7 +30,7 @@ public void onPlayerClick(final PlayerInteractEntityEvent event) {
if(!ItemUtil.isStackValid(InventoryUtil.getItemInHand(event.getPlayer(), event.getHand()))) return;
if(!(event.getRightClicked() instanceof LivingEntity)) return;
CraftBookPlayer player = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());
if(InventoryUtil.getItemInHand(event.getPlayer(), event.getHand()).getType() != Material.LEASH) return;
if(InventoryUtil.getItemInHand(event.getPlayer(), event.getHand()).getType() != Material.LEAD) return;

if (!EventUtil.passesFilter(event)) return;

Expand Down Expand Up @@ -161,7 +161,7 @@ public void onHitchBreak(final HangingBreakByEntityEvent event) {
isOwner = true;
if(isOwner || !(ent instanceof Tameable) || !leadsOwnerBreakOnly || event.getRemover().hasPermission("craftbook.mech.leads.owner-break-only.bypass")) {
((LivingEntity) ent).setLeashHolder(null);
event.getEntity().getWorld().dropItemNaturally(event.getEntity().getLocation(), new ItemStack(Material.LEASH, 1));
event.getEntity().getWorld().dropItemNaturally(event.getEntity().getLocation(), new ItemStack(Material.LEAD, 1));
} else {
amountConnected++;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/sk89q/craftbook/mechanics/Chair.java
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand All @@ -36,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;


/**
Expand Down Expand Up @@ -395,9 +397,8 @@ public void loadConfiguration (YAMLProcessor config, String path) {
chairHealAmount = config.getDouble(path + "regen-health-amount", 1);

config.setComment(path + "blocks", "A list of blocks that can be sat on.");
chairBlocks = ItemInfo.parseListFromString(config.getStringList(path + "blocks", Arrays.asList("WOOD_STAIRS", "COBBLESTONE_STAIRS",
"BRICK_STAIRS", "SMOOTH_STAIRS", "NETHER_BRICK_STAIRS", "SANDSTONE_STAIRS", "SPRUCE_WOOD_STAIRS", "BIRCH_WOOD_STAIRS",
"JUNGLE_WOOD_STAIRS", "QUARTZ_STAIRS", "ACACIA_STAIRS", "DARK_OAK_STAIRS", "PURPUR_STAIRS", "RED_SANDSTONE_STAIRS")));
chairBlocks = ItemInfo.parseListFromString(config.getStringList(path + "blocks",
Tag.STAIRS.getValues().stream().map(material -> material.getKey().toString()).collect(Collectors.toList())));

config.setComment(path + "face-correct-direction", "When the player sits, automatically face them the direction of the chair. (If possible)");
chairFacing = config.getBoolean(path + "face-correct-direction", true);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/sk89q/craftbook/mechanics/CookingPot.java
Expand Up @@ -295,7 +295,8 @@ public int getMultiplier(ChangedSign sign) {
}

private enum Ingredients {
COAL(Material.COAL, 40), COALBLOCK(Material.COAL_BLOCK, 360), LAVA(Material.LAVA_BUCKET, 6000), BLAZE(Material.BLAZE_ROD, 500), BLAZEDUST(Material.BLAZE_POWDER, 250), SNOWBALL(Material.SNOW_BALL, -40), SNOW(Material.SNOW_BLOCK, -100), ICE(Material.ICE, -1000);
COAL(Material.COAL, 40), COALBLOCK(Material.COAL_BLOCK, 360), LAVA(Material.LAVA_BUCKET, 6000), BLAZE(Material.BLAZE_ROD, 500),
BLAZEDUST(Material.BLAZE_POWDER, 250), SNOWBALL(Material.SNOWBALL, -40), SNOW(Material.SNOW_BLOCK, -100), ICE(Material.ICE, -1000);

private Material id;
private int mult;
Expand Down

0 comments on commit 8d75bad

Please sign in to comment.