From a2ddd702cb65e0b3b9fadd3dcc0d3ece321837f1 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 12 Feb 2015 15:53:49 +1100 Subject: [PATCH] potion effects and banners --- .../plot/object/entity/EntityWrapper.java | 4 ++ .../plot/object/entity/LivingEntityStats.java | 4 ++ .../plot/util/ChunkManager.java | 37 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java index 15f2e8164..3773616bd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/EntityWrapper.java @@ -72,6 +72,9 @@ public class EntityWrapper { entity.setCustomName(this.lived.name); entity.setCustomNameVisible(this.lived.visible); } + if (this.lived.potions != null && this.lived.potions.size() > 0) { + entity.addPotionEffects(this.lived.potions); + } entity.setRemainingAir(this.lived.air); entity.setRemoveWhenFarAway(this.lived.persistent); @@ -98,6 +101,7 @@ public class EntityWrapper { public void storeLiving(final LivingEntity lived) { this.lived = new LivingEntityStats(); + this.lived.potions = lived.getActivePotionEffects(); this.lived.loot = lived.getCanPickupItems(); this.lived.name = lived.getCustomName(); this.lived.visible = lived.isCustomNameVisible(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/LivingEntityStats.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/LivingEntityStats.java index dcfd400fe..e482a63b8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/LivingEntityStats.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/entity/LivingEntityStats.java @@ -1,6 +1,9 @@ package com.intellectualcrafters.plot.object.entity; +import java.util.Collection; + import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; public class LivingEntityStats { @@ -22,5 +25,6 @@ public class LivingEntityStats { public ItemStack boots; public ItemStack leggings; public ItemStack chestplate; + public Collection potions; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 989d5f53a..cd4ffd0a5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -8,11 +8,13 @@ import java.util.HashSet; import org.apache.commons.lang.mutable.MutableInt; import org.bukkit.Bukkit; import org.bukkit.Chunk; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Note; import org.bukkit.SkullType; import org.bukkit.World; +import org.bukkit.block.Banner; import org.bukkit.block.Beacon; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -29,6 +31,8 @@ import org.bukkit.block.Jukebox; import org.bukkit.block.NoteBlock; import org.bukkit.block.Sign; import org.bukkit.block.Skull; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.inventory.Inventory; @@ -117,6 +121,8 @@ public class ChunkManager { private static HashMap cmdData; private static HashMap signContents; private static HashMap noteBlockContents; + private static HashMap> bannerColors; + private static HashMap bannerBase; private static HashSet entities; @@ -234,6 +240,8 @@ public class ChunkManager { noteBlockContents = new HashMap<>(); signContents = new HashMap<>(); cmdData = new HashMap<>(); + bannerBase= new HashMap<>(); + bannerColors = new HashMap<>(); entities = new HashSet<>(); } @@ -425,6 +433,22 @@ public class ChunkManager { } else { PlotMain.sendConsoleSenderMessage("&c[WARN] Plot clear failed to regenerate furnace: "+loc.x + x_offset+","+loc.y+","+loc.z + z_offset); } } + + for (BlockLoc loc: bannerBase.keySet()) { + Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + BlockState state = block.getState(); + if (state instanceof Banner) { + Banner banner = (Banner) state; + byte base = bannerBase.get(loc); + ArrayList colors = bannerColors.get(loc); + banner.setBaseColor(DyeColor.values()[base]); + for (Byte[] color : colors) { + banner.addPattern(new Pattern(DyeColor.getByDyeData(color[1]), PatternType.values()[color[0]])); + } + state.update(true); + } + else { PlotMain.sendConsoleSenderMessage("&c[WARN] Plot clear failed to regenerate banner: "+loc.x + x_offset+","+loc.y+","+loc.z + z_offset); } + } } public static void saveBlock(World world, int maxY, int x, int z) { @@ -537,6 +561,19 @@ public class ChunkManager { short rot = (short) getOrdinal(BlockFace.values(), skull.getRotation()); skullData.put(bl, new Object[] {o, rot, skulltype}); break; + case 176: + case 177: + bl = new BlockLoc(x, y, z); + Banner banner = (Banner) block.getState(); + byte base = getOrdinal(DyeColor.values(), banner.getBaseColor()); + ArrayList types = new ArrayList<>(); + + for (Pattern pattern : banner.getPatterns()) { + types.add(new Byte[] {getOrdinal(PatternType.values(), pattern.getPattern()), pattern.getColor().getDyeData() }); + } + bannerBase.put(bl, base); + bannerColors.put(bl, types); + break; } } }