Permalink
Browse files

Cut down massively on usage of ItemInfo.

  • Loading branch information...
me4502 committed Aug 16, 2018
1 parent c56a244 commit 8caa4e1c615340452010027abc22b606f15cb327
Showing with 2,865 additions and 3,413 deletions.
  1. +43 −41 src/main/java/com/sk89q/craftbook/mechanics/BounceBlocks.java
  2. +10 −7 src/main/java/com/sk89q/craftbook/mechanics/Chair.java
  3. +11 −4 src/main/java/com/sk89q/craftbook/mechanics/Footprints.java
  4. +27 −5 src/main/java/com/sk89q/craftbook/mechanics/Snow.java
  5. +16 −13 src/main/java/com/sk89q/craftbook/mechanics/TreeLopper.java
  6. +0 −2 src/main/java/com/sk89q/craftbook/mechanics/area/simple/Door.java
  7. +8 −9 src/main/java/com/sk89q/craftbook/mechanics/cauldron/legacy/CauldronCookbook.java
  8. +4 −4 src/main/java/com/sk89q/craftbook/mechanics/drops/BlockCustomDropDefinition.java
  9. +4 −4 src/main/java/com/sk89q/craftbook/mechanics/drops/CustomDrops.java
  10. +8 −1 src/main/java/com/sk89q/craftbook/mechanics/drops/legacy/LegacyCustomDropManager.java
  11. +16 −18 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/BlockBreaker.java
  12. +9 −10 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/SetBlockAdmin.java
  13. +5 −8 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/SetBlockChest.java
  14. +8 −7 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/sensors/BlockSensor.java
  15. +6 −7 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartBlockMechanism.java
  16. +11 −9 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartBooster.java
  17. +3 −1 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartDeposit.java
  18. +3 −2 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartDispenser.java
  19. +3 −2 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartEjector.java
  20. +8 −8 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartLift.java
  21. +5 −5 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartMaxSpeed.java
  22. +9 −10 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartMechanismBlocks.java
  23. +3 −2 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartMessenger.java
  24. +6 −6 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartReverser.java
  25. +3 −2 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartSorter.java
  26. +5 −4 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartStation.java
  27. +7 −7 src/main/java/com/sk89q/craftbook/mechanics/minecart/blocks/CartTeleporter.java
  28. +15 −12 src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java
  29. +2,494 −3,099 src/main/resources/defaults/books.txt
  30. +29 −1 src/main/resources/defaults/ic-config.yml
  31. +84 −101 src/main/resources/defaults/mechanisms.yml
  32. +2 −2 src/test/java/com/sk89q/craftbook/mechanics/TreeLopperTest.java
@@ -5,11 +5,15 @@
import com.sk89q.craftbook.CraftBookPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.bukkit.util.CraftBookBukkitUtil;
import com.sk89q.craftbook.util.BlockSyntax;
import com.sk89q.craftbook.util.EventUtil;
import com.sk89q.craftbook.util.ItemInfo;
import com.sk89q.craftbook.util.RegexUtil;
import com.sk89q.craftbook.util.SignUtil;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.blocks.Blocks;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.apache.commons.lang.StringUtils;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -27,15 +31,15 @@
public class BounceBlocks extends AbstractCraftBookMechanic {
List<ItemInfo> blocks;
private List<BlockStateHolder> blocks;
private double sensitivity;
private Map<ItemInfo, Vector> autoBouncers = new HashMap<>();
private Map<BlockStateHolder, Vector> autoBouncers = new HashMap<>();
@Override
public void loadConfiguration (YAMLProcessor config, String path) {
config.setComment(path + "blocks", "A list of blocks that can be jumped on.");
blocks = ItemInfo.parseListFromString(config.getStringList(path + "blocks", Collections.singletonList("DIAMOND_BLOCK")));
blocks = BlockSyntax.getBlocks(config.getStringList(path + "blocks", Collections.singletonList(BlockTypes.DIAMOND_BLOCK.getId())), true);
config.setComment(path + "sensitivity", "The sensitivity of jumping.");
sensitivity = config.getDouble(path + "sensitivity", 0.1);
@@ -63,7 +67,7 @@ public void loadConfiguration (YAMLProcessor config, String path) {
z = Double.parseDouble(bits[2]);
}
ItemInfo block = new ItemInfo(key);
BlockStateHolder block = BlockSyntax.getBlock(key, true);
autoBouncers.put(block, new Vector(x,y,z));
}
@@ -79,60 +83,58 @@ public void onPlayerMove(final PlayerMoveEvent event) {
Block block = event.getFrom().getBlock().getRelative(BlockFace.DOWN);
for(ItemInfo check : blocks) {
if(check.isSame(block)) {
if(Blocks.containsFuzzy(blocks, BukkitAdapter.adapt(block.getBlockData()))) {
CraftBookPlugin.logDebugMessage("Player jumped on a block that is a BoucneBlock!", "bounce-blocks");
CraftBookPlugin.logDebugMessage("Player jumped on a block that is a BoucneBlock!", "bounce-blocks");
//Boom, headshot.
Block sign = block.getRelative(BlockFace.DOWN);
//Boom, headshot.
Block sign = block.getRelative(BlockFace.DOWN);
if(SignUtil.isSign(sign)) {
final ChangedSign s = CraftBookBukkitUtil.toChangedSign(sign);
if(SignUtil.isSign(sign)) {
final ChangedSign s = CraftBookBukkitUtil.toChangedSign(sign);
if(s.getLine(1).equals("[Jump]")) {
if(s.getLine(1).equals("[Jump]")) {
CraftBookPlugin.logDebugMessage("Jump sign found where player jumped!", "bounce-blocks");
CraftBookPlugin.logDebugMessage("Jump sign found where player jumped!", "bounce-blocks");
double x = 0,y,z = 0;
boolean straight = s.getLine(2).startsWith("!");
double x = 0,y,z = 0;
boolean straight = s.getLine(2).startsWith("!");
String[] bits = RegexUtil.COMMA_PATTERN.split(StringUtils.replace(s.getLine(2), "!", ""));
if (bits.length == 0) {
String[] bits = RegexUtil.COMMA_PATTERN.split(StringUtils.replace(s.getLine(2), "!", ""));
if (bits.length == 0) {
y = 0.5;
} else if (bits.length == 1) {
try {
y = Double.parseDouble(bits[0]);
} catch (NumberFormatException e) {
y = 0.5;
} else if (bits.length == 1) {
try {
y = Double.parseDouble(bits[0]);
} catch (NumberFormatException e) {
y = 0.5;
}
} else {
x = Double.parseDouble(bits[0]);
y = Double.parseDouble(bits[1]);
z = Double.parseDouble(bits[2]);
}
} else {
x = Double.parseDouble(bits[0]);
y = Double.parseDouble(bits[1]);
z = Double.parseDouble(bits[2]);
}
if(!straight) {
Vector facing = event.getTo().getDirection();
if(!straight) {
//Find out the angle they are facing. This is completely to do with horizontals. No verticals are taken into account.
double angle = Math.atan2(facing.getX(), facing.getZ());
Vector facing = event.getTo().getDirection();
x = Math.sin(angle)*x;
z = Math.cos(angle)*z;
}
//Find out the angle they are facing. This is completely to do with horizontals. No verticals are taken into account.
double angle = Math.atan2(facing.getX(), facing.getZ());
event.getPlayer().setVelocity(new Vector(x,y,z));
event.getPlayer().setFallDistance(-20f);
x = Math.sin(angle)*x;
z = Math.cos(angle)*z;
}
return;
event.getPlayer().setVelocity(new Vector(x,y,z));
event.getPlayer().setFallDistance(-20f);
}
return;
}
}
for(Entry<ItemInfo, Vector> entry : autoBouncers.entrySet()) {
if(entry.getKey().isSame(block)) {
for(Entry<BlockStateHolder, Vector> entry : autoBouncers.entrySet()) {
if(entry.getKey().equalsFuzzy(BukkitAdapter.adapt(block.getBlockData()))) {
CraftBookPlugin.logDebugMessage("Player jumped on a auto block that is a BoucneBlock!", "bounce-blocks");
@@ -9,18 +9,22 @@
import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.CraftBookPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.util.BlockSyntax;
import com.sk89q.craftbook.util.BlockUtil;
import com.sk89q.craftbook.util.EventUtil;
import com.sk89q.craftbook.util.ItemInfo;
import com.sk89q.craftbook.util.LocationUtil;
import com.sk89q.craftbook.util.ProtectionUtil;
import com.sk89q.craftbook.util.SignUtil;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.blocks.Blocks;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -200,7 +204,7 @@ public void onRightClick(PlayerInteractEvent event) {
return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getClickedBlock() == null || !chairBlocks.contains(new ItemInfo(event.getClickedBlock())))
if (event.getClickedBlock() == null || !Blocks.containsFuzzy(chairBlocks, BukkitAdapter.adapt(event.getClickedBlock().getBlockData())))
return;
CraftBookPlayer lplayer = CraftBookPlugin.inst().wrapPlayer(event.getPlayer());
@@ -293,7 +297,7 @@ public void run() {
continue;
}
if (!chairBlocks.contains(new ItemInfo(pl.getValue().location)) || !p.getWorld().equals(pl.getValue().location.getWorld()) || LocationUtil.getDistanceSquared(p.getLocation(), pl.getValue().location.getLocation()) > 2)
if (!Blocks.containsFuzzy(chairBlocks, BukkitAdapter.adapt(pl.getValue().location.getBlockData())) || !p.getWorld().equals(pl.getValue().location.getWorld()) || LocationUtil.getDistanceSquared(p.getLocation(), pl.getValue().location.getLocation()) > 2)
removeChair(p);
else {
addChair(p, pl.getValue().location, null); // For any new players.
@@ -382,7 +386,7 @@ public void disable () {
private boolean chairAllowHeldBlock;
private boolean chairHealth;
private double chairHealAmount;
private List<ItemInfo> chairBlocks;
private List<BlockStateHolder> chairBlocks;
private boolean chairFacing;
private boolean chairRequireSign;
private int chairMaxDistance;
@@ -401,8 +405,7 @@ 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",
Tag.STAIRS.getValues().stream().map(material -> material.getKey().toString()).collect(Collectors.toList())));
chairBlocks = BlockSyntax.getBlocks(config.getStringList(path + "blocks", BlockCategories.STAIRS.getAll().stream().map(BlockType::getId).collect(Collectors.toList())), true);
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);
@@ -2,9 +2,13 @@
import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.util.BlockSyntax;
import com.sk89q.craftbook.util.EventUtil;
import com.sk89q.craftbook.util.ItemInfo;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.blocks.Blocks;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
@@ -47,7 +51,7 @@ public void onPlayerMove(final PlayerMoveEvent event) {
} else if (event.getPlayer().getLocation().getY() != below.getY() + 1)
return;
if(blocks.contains(new ItemInfo(below))) {
if(Blocks.containsFuzzy(blocks, BukkitAdapter.adapt(below.getBlockData()))) {
if(footsteps.contains(event.getPlayer().getName()))
return;
@@ -85,12 +89,15 @@ public void disable () {
footsteps = null;
}
List<ItemInfo> blocks;
private List<BlockStateHolder> blocks;
@Override
public void loadConfiguration (YAMLProcessor config, String path) {
config.setComment(path + "blocks", "The list of blocks that footprints appear on.");
blocks = ItemInfo.parseListFromString(config.getStringList(path + "blocks", Arrays.asList("DIRT", "SAND", "SNOW", "SNOW_BLOCK", "ICE")));
blocks = BlockSyntax.getBlocks(config.getStringList(path + "blocks", Arrays.asList(
BlockTypes.DIRT.getId(), BlockTypes.SAND.getId(), BlockTypes.SNOW.getId(), BlockTypes.SNOW_BLOCK.getId(), BlockTypes.ICE.getId(),
BlockTypes.RED_SAND.getId()
)), true);
}
}
@@ -1,13 +1,18 @@
package com.sk89q.craftbook.mechanics;
import com.google.common.collect.Lists;
import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.CraftBookPlayer;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.util.BlockSyntax;
import com.sk89q.craftbook.util.BlockUtil;
import com.sk89q.craftbook.util.EventUtil;
import com.sk89q.craftbook.util.ItemInfo;
import com.sk89q.craftbook.util.ProtectionUtil;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.blocks.Blocks;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
@@ -34,7 +39,12 @@
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.BlockVector;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
/**
* Snow fall mechanism. Builds up/tramples snow
@@ -95,7 +105,7 @@ private boolean canLandOn(Block block) {
private boolean isReplacable(Block block) {
return !(block.getType() == Material.WATER)
&& (BlockUtil.isBlockReplacable(block.getType())
|| realisticReplacables.contains(new ItemInfo(block)));
|| Blocks.containsFuzzy(realisticReplacables, BukkitAdapter.adapt(block.getBlockData())));
}
@EventHandler(priority = EventPriority.HIGH)
@@ -528,13 +538,25 @@ public int hashCode() {
private boolean pileHigh;
private int maxPileHeight;
private boolean jumpTrample;
private List<ItemInfo> realisticReplacables;
private List<BlockStateHolder> realisticReplacables;
private int animationTicks;
private boolean freezeWater;
private boolean meltSunlight;
private boolean meltPartial;
private boolean animateFalling;
private static List<String> getDefaultReplacables() {
return Lists.newArrayList(
BlockTypes.DEAD_BUSH.getId(),
BlockTypes.GRASS.getId(),
BlockTypes.DANDELION.getId(),
BlockTypes.POPPY.getId(),
BlockTypes.BROWN_MUSHROOM.getId(),
BlockTypes.RED_MUSHROOM.getId(),
BlockTypes.FIRE.getId(),
BlockTypes.FERN.getId());
}
@Override
public void loadConfiguration (YAMLProcessor config, String path) {
@@ -566,7 +588,7 @@ public void loadConfiguration (YAMLProcessor config, String path) {
maxPileHeight = config.getInt(path + "max-pile-height", 3);
config.setComment(path + "replacable-blocks", "A list of blocks that can be replaced by realistic snow.");
realisticReplacables = ItemInfo.parseListFromString(config.getStringList(path + "replacable-blocks", Arrays.asList("DEAD_BUSH", "LONG_GRASS", "YELLOW_FLOWER", "RED_ROSE", "BROWN_MUSHROOM", "RED_MUSHROOM", "FIRE")));
realisticReplacables = BlockSyntax.getBlocks(config.getStringList(path + "replacable-blocks", getDefaultReplacables()), true);
config.setComment(path + "animate-falling", "Cause the snow to fall slowly (May be intensive).");
animateFalling = config.getBoolean(path + "animate-falling", false);
Oops, something went wrong.

0 comments on commit 8caa4e1

Please sign in to comment.