Skip to content
Permalink
Browse files

Use PaperLib for some of the more intense BlockState's

  • Loading branch information...
me4502 committed Nov 24, 2018
1 parent a2f3e40 commit a28146573ce385f681c55f90034f1e2f9219ae2e
@@ -98,6 +98,7 @@ allprojects {
compile 'com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT'
compile 'com.sk89q.worldguard:worldguard-core:7.0.0-SNAPSHOT'
compile 'com.sk89q.worldguard:worldguard-legacy:7.0.0-SNAPSHOT'
compile "io.papermc:paperlib:1.0.1"
compile 'com.sk89q:squirrelid:0.1.0'
compile 'net.milkbowl.vault:VaultAPI:1.6'
compile 'com.comphenix.protocol:ProtocolLib-API:4.4.0-SNAPSHOT'
@@ -150,6 +151,7 @@ allprojects {
}
}
relocate 'com.sk89q.squirrelid', 'com.sk89q.craftbook.util.profile'
relocate 'io.papermc.lib', 'com.sk89q.craftbook.bukkit.paperlib'
exclude 'GradleStart**'
exclude '.cache'
exclude 'LICENSE*'
@@ -5,6 +5,7 @@
import com.sk89q.craftbook.mechanics.variables.VariableManager;
import com.sk89q.craftbook.util.ParsingUtil;
import com.sk89q.craftbook.util.RegexUtil;
import io.papermc.lib.PaperLib;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
@@ -24,7 +25,9 @@
public ChangedSign(Block block, String[] lines, CraftBookPlayer player) {
this(block, lines);

checkPlayerVariablePermissions(player);
if (player != null) {
checkPlayerVariablePermissions(player);
}
}

public ChangedSign(Block block, String[] lines) {
@@ -56,7 +59,7 @@ public void checkPlayerVariablePermissions(CraftBookPlayer player) {
} else
key = "global";

if(player != null && !VariableCommands.hasVariablePermission(((BukkitCraftBookPlayer) player).getPlayer(), key, var, "use"))
if(!VariableCommands.hasVariablePermission(((BukkitCraftBookPlayer) player).getPlayer(), key, var, "use"))
setLine(i, StringUtils.replace(line, '%' + key + '|' + var + '%', ""));
}
}
@@ -69,7 +72,7 @@ public Block getBlock() {

public Sign getSign() {
if (this.sign == null) {
this.sign = (Sign) this.block.getState();
this.sign = (Sign) PaperLib.getBlockState(this.block, false).getState();
}
return sign;
}
@@ -158,8 +161,8 @@ public boolean hasChanged () {
}

public void flushLines () {
this.sign = (Sign) this.block.getState();
this.lines = this.sign.getLines();
this.sign = null;
this.lines = this.getSign().getLines();
if (this.oldLines == null) {
this.oldLines = new String[lines.length];
}
@@ -102,6 +102,7 @@
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import io.papermc.lib.PaperLib;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -502,6 +503,8 @@ public void playerJoin(PlayerJoinEvent event) {
Bukkit.getScheduler().runTaskTimer(this,
() -> getLogger().warning(ChatColor.RED + "Warning! You have no mechanics enabled, the plugin will appear to do nothing until a feature is enabled!"), 20L, 20*60*5);
}

PaperLib.suggestPaper(this);
}

private YAMLProcessor mechanismsConfig;
@@ -31,14 +31,15 @@
import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.Chest;
import org.bukkit.block.data.type.Piston;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.PistonBaseMaterial;
import org.bukkit.util.Vector;

import java.util.HashSet;
@@ -129,7 +130,7 @@ public void onSignChange(SignChangeEvent event) {

if(ProtectionUtil.shouldUseProtection()) {
if (type == Types.BOUNCE || type == Types.CRUSH) {
PistonBaseMaterial pis = (PistonBaseMaterial) block.getState().getData();
Piston pis = (Piston) block.getBlockData();
Block off = block.getRelative(pis.getFacing());
if (!ProtectionUtil.canBuild(event.getPlayer(), off, false)) {
if (CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
@@ -138,7 +139,7 @@ public void onSignChange(SignChangeEvent event) {
return;
}
} else if (type == Types.SUPERPUSH || type == Types.SUPERSTICKY) {
PistonBaseMaterial pis = (PistonBaseMaterial) block.getState().getData();
Piston pis = (Piston) block.getBlockData();

int distance = 10;
try {
@@ -177,7 +178,7 @@ public void onBlockRedstoneChange(SourcedBlockRedstoneEvent event) {
Set<Tuple2<Types, Block>> types = new HashSet<>();

// check if this looks at all like something we're interested in first
PistonBaseMaterial piston = (PistonBaseMaterial) event.getBlock().getState().getData();
Piston piston = (Piston) event.getBlock().getBlockData();
Block sign;
Types type;

@@ -226,7 +227,7 @@ public void onBlockRedstoneChange(SourcedBlockRedstoneEvent event) {
}
}

public void crush(Block trigger, PistonBaseMaterial piston, ChangedSign signState) {
public void crush(Block trigger, Piston piston, ChangedSign signState) {

//piston.setPowered(false);

@@ -246,9 +247,9 @@ public void crush(Block trigger, PistonBaseMaterial piston, ChangedSign signStat
trigger.getRelative(piston.getFacing()).setType(Material.AIR, false);
}

public void bounce(Block trigger, PistonBaseMaterial piston, ChangedSign signState) {
public void bounce(Block trigger, Piston piston, ChangedSign signState) {

if (piston.isSticky()) return;
if (piston.getMaterial() == Material.STICKY_PISTON) return;

double mult;
try {
@@ -277,9 +278,9 @@ public void bounce(Block trigger, PistonBaseMaterial piston, ChangedSign signSta
}
}

public void superSticky(final Block trigger, final PistonBaseMaterial piston, final ChangedSign signState) {
public void superSticky(final Block trigger, final Piston piston, final ChangedSign signState) {

if (!piston.isSticky()) return;
if (piston.getMaterial() != Material.STICKY_PISTON) return;

if (trigger.getRelative(piston.getFacing()).getType() == Material.PISTON_HEAD || trigger.getRelative(piston.getFacing()).getType() == Material.MOVING_PISTON) {

@@ -324,7 +325,7 @@ public void superSticky(final Block trigger, final PistonBaseMaterial piston, fi
}
}

public void superPush(final Block trigger, final PistonBaseMaterial piston, ChangedSign signState) {
public void superPush(final Block trigger, final Piston piston, ChangedSign signState) {
if (trigger.getRelative(piston.getFacing()).getType() != Material.PISTON_HEAD && trigger.getRelative(piston.getFacing()).getType() != Material.MOVING_PISTON) {
int block = 10;
int amount = 1;
@@ -408,18 +409,14 @@ public static boolean copyData(Block from, Block to) {
}

private boolean canPistonPushBlock(Block block) {
if (block.getState() instanceof DoubleChest) return false;
BlockData blockData = block.getBlockData();
if (blockData instanceof Chest && ((Chest) blockData).getType() != Chest.Type.SINGLE) return false;

if (Blocks.containsFuzzy(pistonsMovementBlacklist, BukkitAdapter.adapt(block.getBlockData()))) {
return false;
}

switch (block.getType()) {
case MOVING_PISTON:
return false;
default:
return true;
}
return block.getType() != Material.MOVING_PISTON;
}

public enum Types {
@@ -437,8 +437,7 @@ else if(event.getLine(1).equalsIgnoreCase("[mc0421]"))
}

Bukkit.getServer().getScheduler().runTask(CraftBookPlugin.inst(), () -> {

ChangedSign sign = new ChangedSign(event.getBlock(), event.getLines());
ChangedSign sign = CraftBookPlugin.inst().getNmsAdapter().getChangedSign(event.getBlock(), event.getLines(), null);

//WorldEdit offset/radius tools.
ICUtil.parseSignFlags(player, sign);
@@ -60,7 +60,8 @@ public boolean isAlwaysST() {
public void trigger(ChipState chip) {

String setting = getSign().getLine(2).toUpperCase(Locale.ENGLISH);
if (chip.getInput(0) && setting.contains("H") || !chip.getInput(0) && setting.contains("L")) {
boolean triggered = chip.getInput(0);
if (triggered && setting.contains("H") || !triggered && setting.contains("L")) {
// Trigger condition!
int colon = setting.indexOf(':');
if (colon <= 0) return;
@@ -140,7 +141,7 @@ public void verify(ChangedSign sign) throws ICVerificationException {
ticks = Math.max(ticks, 2);
ticks = Math.min(ticks, 6000);

sign.setLine(2, Integer.toString(ticks) + ":" + (hi ? "H" : "") + (lo ? "L" : ""));
sign.setLine(2, ticks + ":" + (hi ? "H" : "") + (lo ? "L" : ""));
sign.setLine(3, "0");
sign.update(false);
}
@@ -15,6 +15,7 @@
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;

public final class ProtectionUtil {

@@ -50,7 +51,7 @@ public static boolean canBuild(Player player, Block block, boolean build) {
CompatabilityUtil.disableInterferences(player);
BlockEvent event;
if (build)
event = new BlockPlaceEvent(block, block.getState(), block.getRelative(0, -1, 0), player.getItemInHand(), player, true);
event = new BlockPlaceEvent(block, block.getState(), block.getRelative(0, -1, 0), player.getInventory().getItemInMainHand(), player, true, EquipmentSlot.HAND);
else
event = new BlockBreakEvent(block, player);
EventUtil.ignoreEvent(event);

0 comments on commit a281465

Please sign in to comment.
You can’t perform that action at this time.