From d418bb276e821a54a50998049e8f76700aeb4ad0 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 1 Jul 2018 13:57:08 +0100 Subject: [PATCH] Optimised UtilBlockText --- .../core/common/util/UtilBlockText.java | 107 ++++-------------- .../cakewars/kits/perk/PerkSlowSnowball.java | 2 +- 2 files changed, 20 insertions(+), 89 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlockText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlockText.java index 0242d205c..358457d22 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlockText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlockText.java @@ -1,11 +1,13 @@ package mineplex.core.common.util; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Map; +import java.util.Set; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -19,77 +21,7 @@ public class UtilBlockText CENTER } - public static HashMap alphabet = new HashMap(); - - public static ArrayList GetTextLocations(String string, Location loc, BlockFace face) - { - if (alphabet.isEmpty()) - PopulateAlphabet(); - - ArrayList locs = new ArrayList(); - - Block block = loc.getBlock(); - - //Get Width - int width = 0; - for (char c : string.toLowerCase().toCharArray()) - { - int[][] letter = alphabet.get(c); - - if (letter == null) - continue; - - width += (letter[0].length+1) * 3; - } - - //Shift Blocks - block = block.getRelative(face, (-1 * width/2) + 1); - - - //Clean - World world = block.getWorld(); - int bX = block.getX(); - int bY = block.getY(); - int bZ = block.getZ(); - - //Make Blocks - for (char c : string.toLowerCase().toCharArray()) - { - int[][] letter = alphabet.get(c); - - if (letter == null) - continue; - - for (int x=0 ; x alphabet = new HashMap<>(); public static Collection MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align) { @@ -98,7 +30,7 @@ public class UtilBlockText public static Collection MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align, boolean setAir) { - HashSet changes = new HashSet(); + Set changes = new HashSet<>(); if (alphabet.isEmpty()) PopulateAlphabet(); @@ -139,24 +71,21 @@ public class UtilBlockText if (align == TextAlign.CENTER) for (int i=-64 ; i<=64 ; i++) { - if (world.getBlockAt(bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ()).getTypeId() == id) - MapUtil.ChunkBlockSet(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0, true); + MapUtil.QuickChangeBlockAt(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), Material.AIR); } if (align == TextAlign.LEFT) for (int i=0 ; i<=128 ; i++) { - if (world.getBlockAt(bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ()).getTypeId() == id) - MapUtil.ChunkBlockSet(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0, true); + MapUtil.QuickChangeBlockAt(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), Material.AIR); } if (align == TextAlign.RIGHT) for (int i=-128 ; i<=0 ; i++) { - if (world.getBlockAt(bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ()).getTypeId() == id) - MapUtil.ChunkBlockSet(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0, true); + MapUtil.QuickChangeBlockAt(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), Material.AIR); } @@ -177,26 +106,28 @@ public class UtilBlockText if (letter == null) continue; - for (int x=0 ; x