diff --git a/Prism/src/main/java/network/darkhelmet/prism/PrismConfig.java b/Prism/src/main/java/network/darkhelmet/prism/PrismConfig.java index 1db60c9e..16537f4d 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/PrismConfig.java +++ b/Prism/src/main/java/network/darkhelmet/prism/PrismConfig.java @@ -128,6 +128,7 @@ public FileConfiguration getConfig() { config.addDefault("prism.tracking.block-shift", true); config.addDefault("prism.tracking.block-spread", true); config.addDefault("prism.tracking.block-use", true); + config.addDefault("prism.tracking.block-fertilize", true); config.addDefault("prism.tracking.bucket-fill", true); config.addDefault("prism.tracking.bonemeal-use", true); config.addDefault("prism.tracking.container-access", true); @@ -179,6 +180,7 @@ public FileConfiguration getConfig() { config.addDefault("prism.tracking.player-trade", false); config.addDefault("prism.tracking.portal-create", true); config.addDefault("prism.tracking.potion-splash", true); + config.addDefault("prism.tracking.potion-lingering", true); config.addDefault("prism.tracking.sheep-eat", true); config.addDefault("prism.tracking.sign-change", true); config.addDefault("prism.tracking.spawnegg-use", true); diff --git a/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionFactory.java b/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionFactory.java index 88eb4cf0..f9aefbb5 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionFactory.java +++ b/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionFactory.java @@ -4,6 +4,7 @@ import network.darkhelmet.prism.actions.BlockChangeAction; import network.darkhelmet.prism.actions.BlockFallAction; import network.darkhelmet.prism.actions.BlockShiftAction; +import network.darkhelmet.prism.actions.BonemealUseAction; import network.darkhelmet.prism.actions.EntityAction; import network.darkhelmet.prism.actions.EntityTravelAction; import network.darkhelmet.prism.actions.GrowAction; @@ -119,7 +120,7 @@ public static Handler createBlockChange(String actionType, Location loc, Materia } /** - * BlockPlaceEvent | EntityBlockFormEvent. + * BlockPlaceEvent | EntityBlockFormEvent | BlockFertilizeEvent. * * @param actionType type * @param oldMat old @@ -584,6 +585,34 @@ public static Handler createUse(String actionType, Material item, Block block, O return a; } + /** + * BonemealUseAction. + * + * @param block the block acted on + * @param player the acting player + */ + public static Handler createBonemealUse(Block block, Player player) { + final BonemealUseAction a = new BonemealUseAction(); + a.setActionType("bonemeal-use"); + a.setBlock(block); + a.setPlayer(player); + return a; + } + + /** + * BonemealUseAction. + * + * @param block the block acted on + * @param nonPlayer nonplayer + */ + public static Handler createBonemealUse(Block block, String nonPlayer) { + final BonemealUseAction a = new BonemealUseAction(); + a.setActionType("bonemeal-use"); + a.setBlock(block); + a.setSourceName(nonPlayer); + return a; + } + /** * VehicleAction. * diff --git a/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionRegistry.java b/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionRegistry.java index b787d3d9..1d8f2ead 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionRegistry.java +++ b/Prism/src/main/java/network/darkhelmet/prism/actionlibs/ActionRegistry.java @@ -6,6 +6,7 @@ import network.darkhelmet.prism.actions.BlockChangeAction; import network.darkhelmet.prism.actions.BlockFallAction; import network.darkhelmet.prism.actions.BlockShiftAction; +import network.darkhelmet.prism.actions.BonemealUseAction; import network.darkhelmet.prism.actions.EntityAction; import network.darkhelmet.prism.actions.EntityTravelAction; import network.darkhelmet.prism.actions.GrowAction; @@ -161,8 +162,10 @@ private void registerPrismDefaultActions() { BlockChangeAction.class, Il8nHelper.getRawMessage("grew"))); registerAction(new ActionTypeImpl("block-use", false, false, false, BlockAction.class, Il8nHelper.getRawMessage("used"))); + registerAction(new ActionTypeImpl("block-fertilize", true, true, true, + BlockChangeAction.class, Il8nHelper.getRawMessage("fertilized"))); registerAction(new ActionTypeImpl("bonemeal-use", false, false, false, - UseAction.class, Il8nHelper.getRawMessage("used"))); + BonemealUseAction.class, Il8nHelper.getRawMessage("used-bonemeal"))); registerAction(new ActionTypeImpl("bucket-fill", false, false, false, PlayerAction.class, Il8nHelper.getRawMessage("filled"))); registerAction(new ActionTypeImpl("cake-eat", false, false, false, @@ -261,6 +264,8 @@ private void registerPrismDefaultActions() { PortalCreateAction.class, "created portal")); registerAction(new ActionTypeImpl("potion-splash", false, false, false, PlayerAction.class, Il8nHelper.getRawMessage("potion-throw"))); + registerAction(new ActionTypeImpl("potion-lingering", false, false, false, + PlayerAction.class, Il8nHelper.getRawMessage("potion-throw"))); registerAction(new ActionTypeImpl("prism-drain", false, true, true, PrismRollbackAction.class, Il8nHelper.getRawMessage("drained"))); registerAction(new ActionTypeImpl("prism-extinguish", false, true, true, diff --git a/Prism/src/main/java/network/darkhelmet/prism/actions/BonemealUseAction.java b/Prism/src/main/java/network/darkhelmet/prism/actions/BonemealUseAction.java new file mode 100644 index 00000000..5978f5a9 --- /dev/null +++ b/Prism/src/main/java/network/darkhelmet/prism/actions/BonemealUseAction.java @@ -0,0 +1,34 @@ +package network.darkhelmet.prism.actions; + +import org.bukkit.block.Block; + +public class BonemealUseAction extends GenericAction { + + public void setBlock(Block block) { + setLoc(block.getLocation()); + setMaterial(block.getType()); + } + + /** + * {@inheritDoc} + */ + @Override + public String getNiceName() { + return getMaterial().name().toLowerCase().replace("_", " "); + } + + @Override + public boolean hasExtraData() { + return false; + } + + @Override + public String serialize() { + return null; + } + + @Override + public void deserialize(String data) { + } + +} diff --git a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismBlockEvents.java b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismBlockEvents.java index cf7abf47..5ca68508 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismBlockEvents.java +++ b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismBlockEvents.java @@ -18,7 +18,6 @@ import org.bukkit.block.data.type.Bed; import org.bukkit.block.data.type.Chest; import org.bukkit.block.data.type.Chest.Type; -import org.bukkit.block.data.type.RespawnAnchor; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; diff --git a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java index 21f3b389..fbf849c4 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java +++ b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; +import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.Wither; import org.bukkit.entity.minecart.PoweredMinecart; import org.bukkit.event.EventHandler; @@ -40,6 +41,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityUnleashEvent; +import org.bukkit.event.entity.LingeringPotionSplashEvent; import org.bukkit.event.entity.PlayerLeashEntityEvent; import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; @@ -54,6 +56,7 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; @@ -536,8 +539,20 @@ public void onEntityUnleash(final EntityUnleashEvent event) { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPotionSplashEvent(final PotionSplashEvent event) { + logPotionThrowEvent(event.getEntity(), "potion-splash"); + } - final ProjectileSource source = event.getPotion().getShooter(); + /** + * LingeringPotionSplashEvent. + * @param event LingeringPotionSplashEvent. + */ + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onLingeringPotionSplashEvent(final LingeringPotionSplashEvent event) { + logPotionThrowEvent(event.getEntity(), "potion-lingering"); + } + + private void logPotionThrowEvent(final ThrownPotion thrownPotion, final String actionType) { + final ProjectileSource source = thrownPotion.getShooter(); // Ignore from non-players for the time being if (!(source instanceof Player)) { @@ -546,20 +561,25 @@ public void onPotionSplashEvent(final PotionSplashEvent event) { final Player player = (Player) source; - if (!Prism.getIgnore().event("potion-splash", player)) { + if (!Prism.getIgnore().event(actionType, player)) { return; } - // What type? - // Right now this won't support anything with multiple effects - final Collection potion = event.getPotion().getEffects(); - String name = ""; + final Collection potion = thrownPotion.getEffects(); + final StringBuilder name = new StringBuilder(); for (final PotionEffect eff : potion) { - name = eff.getType().getName().toLowerCase(); + name.append(eff.getType().getName().toLowerCase()).append(", "); } - RecordingQueue.addToQueue(ActionFactory.createPlayer("potion-splash", player, name)); + // No effect, may be water, awkward or something. + if (name.length() == 0) { + PotionMeta potionMeta = (PotionMeta) thrownPotion.getItem().getItemMeta(); + name.append(potionMeta.getBasePotionData().getType().name().toLowerCase()); + } else { + name.setLength(name.length() - 2); + } + RecordingQueue.addToQueue(ActionFactory.createPlayer(actionType, player, name.toString())); } /** diff --git a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismPlayerEvents.java b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismPlayerEvents.java index fdd69cb4..56f91d37 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismPlayerEvents.java +++ b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismPlayerEvents.java @@ -429,8 +429,6 @@ public void onPlayerInteract(final PlayerInteractEvent event) { return; } RecordingQueue.addToQueue(ActionFactory.createBlock("block-use", block, player)); - } else if (MaterialTag.GROWABLE.isTagged(block.getType())) { - recordBoneMealEvent(block, hand, player); } else { switch (block.getType()) { case JUKEBOX: @@ -530,22 +528,6 @@ private void recordCocoaPlantEvent(Block block, ItemStack inhand, BlockFace clic } } - /** - * recordBoneMealEvent. - * - * @param block Block - * @param inhand ItemStack - * @param player Player - */ - private void recordBoneMealEvent(Block block, ItemStack inhand, Player player) { - if (inhand.getType() == Material.BONE_MEAL) { - if (!Prism.getIgnore().event("bonemeal-use", block)) { - return; - } - RecordingQueue.addToQueue(ActionFactory.createUse("bonemeal-use", inhand.getType(), block, player)); - } - } - /** * recordMonsterEggUse. * diff --git a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismWorldEvents.java b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismWorldEvents.java index 9cfed314..86c65679 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismWorldEvents.java +++ b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismWorldEvents.java @@ -7,16 +7,20 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.TreeType; +import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFertilizeEvent; import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.event.world.WorldLoadEvent; +import java.util.List; + public class PrismWorldEvents implements Listener { /** @@ -36,7 +40,8 @@ public void onStructureGrow(final StructureGrowEvent event) { for (final BlockState block : event.getBlocks()) { if (Utilities.isGrowableStructure(block.getType())) { if (event.getPlayer() != null) { - RecordingQueue.addToQueue(ActionFactory.createGrow(type, block, event.getPlayer())); + // Process by #onBlockFertilizeEvent below + return; } else { RecordingQueue.addToQueue(ActionFactory.createGrow(type, block, "Environment")); } @@ -44,6 +49,36 @@ public void onStructureGrow(final StructureGrowEvent event) { } } + /** + * Handle BlockFertilizeEvent. + * @param event BlockFertilizeEvent. + */ + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onBlockFertilizeEvent(BlockFertilizeEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + List blocks = event.getBlocks(); + + if (blocks.size() > 0 && Prism.getIgnore().event("block-fertilize", blocks.get(0).getWorld())) { + for (BlockState newState : blocks) { + Block oldBlock = newState.getBlock(); + if (player != null) { + RecordingQueue.addToQueue(ActionFactory.createBlockChange("block-fertilize", oldBlock.getType(), oldBlock.getBlockData(), newState, player)); + } else { + RecordingQueue.addToQueue(ActionFactory.createBlockChange("block-fertilize", oldBlock.getType(), oldBlock.getBlockData(), newState, "Dispenser")); + } + } + } + + if (Prism.getIgnore().event("bonemeal-use", block)) { + if (player != null) { + RecordingQueue.addToQueue(ActionFactory.createBonemealUse(block, player)); + } else { + RecordingQueue.addToQueue(ActionFactory.createBonemealUse(block, "Dispenser")); + } + } + } + /** * WorldLoadEvent. * @param event WorldLoadEvent diff --git a/Prism/src/main/resources/languages/message.properties b/Prism/src/main/resources/languages/message.properties index 0ca5f975..5e95e939 100644 --- a/Prism/src/main/resources/languages/message.properties +++ b/Prism/src/main/resources/languages/message.properties @@ -125,6 +125,8 @@ trampled=trampled turned-item=turned item unleashed=unleashed used=used +used-bonemeal=used bonemeal on +fertilized=fertilized wand-bad=Sorry, but you may not use for a wand. wand-current=Current Wand . wand-error-type=You need to specify a wand type. Use '/prism ?' for help. diff --git a/Prism/src/main/resources/languages/message_en_au.properties b/Prism/src/main/resources/languages/message_en_au.properties index 7fa5004a..5593bf26 100644 --- a/Prism/src/main/resources/languages/message_en_au.properties +++ b/Prism/src/main/resources/languages/message_en_au.properties @@ -125,6 +125,8 @@ trampled=trampled turned-item=turned item unleashed=unleashed used=used +used-bonemeal=used bonemeal on +fertilized=fertilized wand-bad=Sorry, but you may not use for a wand. wand-current=Current Wand . wand-error-type=You need to specify a wand type. Use '/prism ?' for help. diff --git a/Prism/src/main/resources/languages/message_en_us.properties b/Prism/src/main/resources/languages/message_en_us.properties index 37123da0..0f606734 100644 --- a/Prism/src/main/resources/languages/message_en_us.properties +++ b/Prism/src/main/resources/languages/message_en_us.properties @@ -124,6 +124,8 @@ trampled=trampled turned-item=turned item unleashed=unleashed used=used +used-bonemeal=used bonemeal on +fertilized=fertilized wand-bad=Sorry, but you may not use for a wand. wand-current=Current Wand . wand-error-type=You need to specify a wand type. Use '/prism ?' for help. diff --git a/Prism/src/main/resources/languages/message_zh_cn.properties b/Prism/src/main/resources/languages/message_zh_cn.properties index ff9ed707..04744c1a 100644 --- a/Prism/src/main/resources/languages/message_zh_cn.properties +++ b/Prism/src/main/resources/languages/message_zh_cn.properties @@ -125,6 +125,8 @@ trampled=践踏了 turned-item=旋转了物品 unleashed=解拴了 used=使用了 +used-bonemeal=使用了骨粉于 +fertilized=催化出了 wand-bad=对不起, 但您不能对魔棒使用 . wand-current=目前魔棒 . wand-error-type=您必须指定一个魔棒类型. 使用 '/prism ?' 获取帮助. @@ -266,4 +268,4 @@ help-settings=更改 Prism 核心设置. 参见维基 help-purge=取消或计划数据清理进程 help-what=显示手持物品的信息 help-extended-message=点击每一个指令都会打开维基条目, 可以获取更多信息. -command-settings-batchsize-set=每批次行为数(Batchsize) 已暂时设定为 %1d. 重启记录器以恢复默认值. \ No newline at end of file +command-settings-batchsize-set=每批次行为数(Batchsize) 已暂时设定为 %1d. 重启记录器以恢复默认值.