forked from LogBlock/LogBlock
fix candle logging
This commit is contained in:
@ -22,9 +22,11 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Candle;
|
||||
import org.bukkit.block.data.type.Comparator;
|
||||
import org.bukkit.block.data.type.DaylightDetector;
|
||||
import org.bukkit.block.data.type.Lectern;
|
||||
@ -130,7 +132,7 @@ public class BlockChange implements LookupCacheElement {
|
||||
String typeDetails = getTypeDetails(type, typeState, replaced, replacedState);
|
||||
String replacedDetails = getTypeDetails(replaced, replacedState);
|
||||
|
||||
if (type.getMaterial().equals(replaced.getMaterial())) {
|
||||
if (type.getMaterial().equals(replaced.getMaterial()) || (type.getMaterial() == Material.CAKE && BukkitUtils.isCandleCake(replaced.getMaterial()))) {
|
||||
if (BukkitUtils.isEmpty(type.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("did an unspecified action", INTERACT.getColor()));
|
||||
} else if (ca != null) {
|
||||
@ -211,6 +213,17 @@ public class BlockChange implements LookupCacheElement {
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(createTextComponentWithColor(" to", CREATE.getColor()));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else if (type instanceof Candle && ((Candle) type).getCandles() != ((Candle) replaced).getCandles()) {
|
||||
msg.addExtra(createTextComponentWithColor("added a candle to ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if ((type instanceof Candle || BukkitUtils.isCandleCake(type.getMaterial())) && ((Lightable) type).isLit() != ((Lightable) replaced).isLit()) {
|
||||
if (((Lightable) type).isLit()) {
|
||||
msg.addExtra(createTextComponentWithColor("lit a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("extinguished a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
}
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(replaced));
|
||||
|
@ -5,7 +5,9 @@ import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
@ -16,8 +18,10 @@ import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.type.Cake;
|
||||
import org.bukkit.block.data.type.Candle;
|
||||
import org.bukkit.block.data.type.Comparator;
|
||||
import org.bukkit.block.data.type.Comparator.Mode;
|
||||
import org.bukkit.block.data.type.DaylightDetector;
|
||||
@ -27,10 +31,12 @@ import org.bukkit.block.data.type.Repeater;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.block.data.type.TurtleEgg;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.world.GenericGameEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
@ -40,6 +46,10 @@ public class InteractLogging extends LoggingListener {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
private UUID lastInteractionPlayer;
|
||||
private BlockData lastInteractionBlockData;
|
||||
private Location lastInteractionLocation;
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getPlayer().getWorld());
|
||||
@ -52,6 +62,9 @@ public class InteractLogging extends LoggingListener {
|
||||
final Material type = blockData.getMaterial();
|
||||
final Player player = event.getPlayer();
|
||||
final Location loc = clicked.getLocation();
|
||||
lastInteractionPlayer = player.getUniqueId();
|
||||
lastInteractionBlockData = blockData;
|
||||
lastInteractionLocation = loc;
|
||||
|
||||
switch (type) {
|
||||
case OAK_FENCE_GATE:
|
||||
@ -77,7 +90,10 @@ public class InteractLogging extends LoggingListener {
|
||||
}
|
||||
break;
|
||||
case CAKE:
|
||||
if (wcfg.isLogging(Logging.CAKEEAT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getFoodLevel() < 20) {
|
||||
if (event.hasItem() && BukkitUtils.isCandle(event.getItem().getType()) && event.useItemInHand() != Result.DENY) {
|
||||
BlockData newBlockData = Material.valueOf(event.getItem().getType().name() + "_CAKE").createBlockData();
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
} else if (wcfg.isLogging(Logging.CAKEEAT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getFoodLevel() < 20) {
|
||||
Cake newBlockData = (Cake) blockData.clone();
|
||||
if (newBlockData.getBites() < 6) {
|
||||
newBlockData.setBites(newBlockData.getBites() + 1);
|
||||
@ -271,4 +287,46 @@ public class InteractLogging extends LoggingListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onGenericGameEvent(GenericGameEvent event) {
|
||||
if (lastInteractionPlayer != null && event.getEntity() != null && event.getEntity().getUniqueId().equals(lastInteractionPlayer) && lastInteractionLocation != null && event.getLocation().equals(lastInteractionLocation)) {
|
||||
if (lastInteractionBlockData instanceof Candle) {
|
||||
Candle previousCandle = (Candle) lastInteractionBlockData;
|
||||
if (previousCandle.isLit()) {
|
||||
BlockData newData = lastInteractionLocation.getBlock().getBlockData();
|
||||
if (newData instanceof Candle) {
|
||||
Candle newCandle = (Candle) newData;
|
||||
if (!newCandle.isLit() && !newCandle.isWaterlogged()) {
|
||||
// log candle extinguish
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (lastInteractionBlockData instanceof Lightable && BukkitUtils.isCandleCake(lastInteractionBlockData.getMaterial())) {
|
||||
Lightable previousLightable = (Lightable) lastInteractionBlockData;
|
||||
BlockData newData = lastInteractionLocation.getBlock().getBlockData();
|
||||
if (event.getEvent().equals(GameEvent.EAT)) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getLocation().getWorld());
|
||||
if (wcfg.isLogging(Logging.CAKEEAT)) {
|
||||
// nom nom (don't know why newData is incorrect here)
|
||||
newData = Material.CAKE.createBlockData();
|
||||
((Cake) newData).setBites(1);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
} else if (previousLightable.isLit()) {
|
||||
if (newData instanceof Lightable) {
|
||||
Lightable newLightable = (Lightable) newData;
|
||||
if (!newLightable.isLit()) {
|
||||
// log cake extinguish
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastInteractionPlayer = null;
|
||||
lastInteractionBlockData = null;
|
||||
lastInteractionLocation = null;
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,8 @@ public class BukkitUtils {
|
||||
private static final EnumSet<Material> concreteBlocks;
|
||||
private static final EnumMap<Material, DyeColor> dyes;
|
||||
private static final EnumSet<Material> alwaysWaterlogged;
|
||||
private static final EnumSet<Material> candles;
|
||||
private static final EnumSet<Material> candleCakes;
|
||||
|
||||
static {
|
||||
pressurePlates = EnumSet.noneOf(Material.class);
|
||||
@ -485,6 +487,44 @@ public class BukkitUtils {
|
||||
concreteBlocks.add(Material.WHITE_CONCRETE);
|
||||
concreteBlocks.add(Material.YELLOW_CONCRETE);
|
||||
|
||||
candles = EnumSet.noneOf(Material.class);
|
||||
candles.add(Material.CANDLE);
|
||||
candles.add(Material.BLACK_CANDLE);
|
||||
candles.add(Material.BLUE_CANDLE);
|
||||
candles.add(Material.LIGHT_GRAY_CANDLE);
|
||||
candles.add(Material.BROWN_CANDLE);
|
||||
candles.add(Material.CYAN_CANDLE);
|
||||
candles.add(Material.GRAY_CANDLE);
|
||||
candles.add(Material.GREEN_CANDLE);
|
||||
candles.add(Material.LIGHT_BLUE_CANDLE);
|
||||
candles.add(Material.MAGENTA_CANDLE);
|
||||
candles.add(Material.LIME_CANDLE);
|
||||
candles.add(Material.ORANGE_CANDLE);
|
||||
candles.add(Material.PINK_CANDLE);
|
||||
candles.add(Material.PURPLE_CANDLE);
|
||||
candles.add(Material.RED_CANDLE);
|
||||
candles.add(Material.WHITE_CANDLE);
|
||||
candles.add(Material.YELLOW_CANDLE);
|
||||
|
||||
candleCakes = EnumSet.noneOf(Material.class);
|
||||
candleCakes.add(Material.CANDLE_CAKE);
|
||||
candleCakes.add(Material.BLACK_CANDLE_CAKE);
|
||||
candleCakes.add(Material.BLUE_CANDLE_CAKE);
|
||||
candleCakes.add(Material.LIGHT_GRAY_CANDLE_CAKE);
|
||||
candleCakes.add(Material.BROWN_CANDLE_CAKE);
|
||||
candleCakes.add(Material.CYAN_CANDLE_CAKE);
|
||||
candleCakes.add(Material.GRAY_CANDLE_CAKE);
|
||||
candleCakes.add(Material.GREEN_CANDLE_CAKE);
|
||||
candleCakes.add(Material.LIGHT_BLUE_CANDLE_CAKE);
|
||||
candleCakes.add(Material.MAGENTA_CANDLE_CAKE);
|
||||
candleCakes.add(Material.LIME_CANDLE_CAKE);
|
||||
candleCakes.add(Material.ORANGE_CANDLE_CAKE);
|
||||
candleCakes.add(Material.PINK_CANDLE_CAKE);
|
||||
candleCakes.add(Material.PURPLE_CANDLE_CAKE);
|
||||
candleCakes.add(Material.RED_CANDLE_CAKE);
|
||||
candleCakes.add(Material.WHITE_CANDLE_CAKE);
|
||||
candleCakes.add(Material.YELLOW_CANDLE_CAKE);
|
||||
|
||||
dyes = new EnumMap<>(Material.class);
|
||||
dyes.put(Material.BLACK_DYE, DyeColor.BLACK);
|
||||
dyes.put(Material.BLUE_DYE, DyeColor.BLUE);
|
||||
@ -1079,4 +1119,12 @@ public class BukkitUtils {
|
||||
public static boolean isAlwaysWaterlogged(Material m) {
|
||||
return alwaysWaterlogged.contains(m);
|
||||
}
|
||||
|
||||
public static boolean isCandle(Material m) {
|
||||
return candles.contains(m);
|
||||
}
|
||||
|
||||
public static boolean isCandleCake(Material m) {
|
||||
return candleCakes.contains(m);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user