Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potion and bonemeal changes #46

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions Prism/src/main/java/network/darkhelmet/prism/PrismConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,7 +120,7 @@ public static Handler createBlockChange(String actionType, Location loc, Materia
}

/**
* BlockPlaceEvent | EntityBlockFormEvent.
* BlockPlaceEvent | EntityBlockFormEvent | BlockFertilizeEvent.
*
* @param actionType type
* @param oldMat old
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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<PotionEffect> potion = event.getPotion().getEffects();
String name = "";
final Collection<PotionEffect> 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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand All @@ -36,14 +40,45 @@ 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"));
}
}
}
}

/**
* 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<BlockState> 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
Expand Down
2 changes: 2 additions & 0 deletions Prism/src/main/resources/languages/message.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 <itemName> for a wand.
wand-current=Current Wand <status>.
wand-error-type=You need to specify a wand type. Use '/prism ?' for help.
Expand Down
2 changes: 2 additions & 0 deletions Prism/src/main/resources/languages/message_en_au.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 <itemName> for a wand.
wand-current=Current Wand <disabled>.
wand-error-type=You need to specify a wand type. Use '/prism ?' for help.
Expand Down
2 changes: 2 additions & 0 deletions Prism/src/main/resources/languages/message_en_us.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 <itemName> for a wand.
wand-current=Current Wand <disabled>.
wand-error-type=You need to specify a wand type. Use '/prism ?' for help.
Expand Down
4 changes: 3 additions & 1 deletion Prism/src/main/resources/languages/message_zh_cn.properties
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ trampled=践踏了
turned-item=旋转了物品
unleashed=解拴了
used=使用了
used-bonemeal=使用了骨粉于
fertilized=催化出了
wand-bad=对不起, 但您不能对魔棒使用 <itemName>.
wand-current=目前魔棒 <status>.
wand-error-type=您必须指定一个魔棒类型. 使用 '/prism ?' 获取帮助.
Expand Down Expand Up @@ -266,4 +268,4 @@ help-settings=更改 Prism 核心设置. 参见维基
help-purge=取消或计划数据清理进程
help-what=显示手持物品的信息
help-extended-message=点击每一个指令都会打开维基条目, 可以获取更多信息.
command-settings-batchsize-set=每批次行为数(Batchsize) 已暂时设定为 %1d. 重启记录器以恢复默认值.
command-settings-batchsize-set=每批次行为数(Batchsize) 已暂时设定为 %1d. 重启记录器以恢复默认值.