mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Fix issue with tracking falling sand & gravel.
This commit is contained in:
parent
2f16dbc9b5
commit
db1c0647ed
@ -19,6 +19,7 @@ Version 1.3.13-dev
|
|||||||
+ Added wooden button to the list of items that shouldn't trigger abilities
|
+ Added wooden button to the list of items that shouldn't trigger abilities
|
||||||
+ Added a new feature to fishing. Players will have +10% chance of finding enchanted items when fishing while it's raining
|
+ Added a new feature to fishing. Players will have +10% chance of finding enchanted items when fishing while it's raining
|
||||||
+ Added displaying bonus perks on skill commands
|
+ Added displaying bonus perks on skill commands
|
||||||
|
= Fix issue with Sand/Gravel tracking
|
||||||
= Fix possible NPE when using the PartyAPI to add a player to a party that doesn't exist.
|
= Fix possible NPE when using the PartyAPI to add a player to a party that doesn't exist.
|
||||||
= Fix mcremove command for mySQL
|
= Fix mcremove command for mySQL
|
||||||
= Impact now works with mobs wearing armor
|
= Impact now works with mobs wearing armor
|
||||||
|
@ -78,29 +78,6 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Monitor BlockPhysics events.
|
|
||||||
*
|
|
||||||
* @param event The event to monitor
|
|
||||||
*/
|
|
||||||
// Disabled until a better patch can be applied. This does nothing but flag the wrong block.
|
|
||||||
/*
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
|
||||||
//TODO: Figure out how to REMOVE metadata from the location the sand/gravel fell from.
|
|
||||||
Material type = event.getChangedType();
|
|
||||||
|
|
||||||
if (type == Material.GRAVEL || type == Material.SAND) {
|
|
||||||
Block fallenBlock = event.getBlock().getRelative(BlockFace.UP);
|
|
||||||
|
|
||||||
if (fallenBlock.getType() == type) {
|
|
||||||
mcMMO.placeStore.setTrue(fallenBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor BlockPistonRetract events.
|
* Monitor BlockPistonRetract events.
|
||||||
*
|
*
|
||||||
@ -126,28 +103,12 @@ public class BlockListener implements Listener {
|
|||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
int id = block.getTypeId();
|
int id = block.getTypeId();
|
||||||
Material type = block.getType();
|
|
||||||
|
|
||||||
if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
|
if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
|
||||||
|
|
||||||
/* Code to prevent issues with placed falling Sand/Gravel not being tracked */
|
|
||||||
if (type.equals(Material.SAND) || type.equals(Material.GRAVEL)) {
|
|
||||||
for (int y = -1; y + block.getY() >= 0; y--) {
|
|
||||||
if (block.getRelative(0, y, 0).getType().equals(Material.AIR)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block newLocation = block.getRelative(0, y + 1, 0);
|
|
||||||
mcMMO.placeStore.setTrue(newLocation);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
|
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
|
||||||
if (BlockChecks.shouldBeWatched(block)) {
|
if (BlockChecks.shouldBeWatched(block)) {
|
||||||
if (!((type == Material.SAND || type == Material.GRAVEL) && block.getRelative(BlockFace.DOWN).getType() == Material.AIR)) { //Don't wanna track sand that's gonna fall.
|
mcMMO.placeStore.setTrue(block);
|
||||||
mcMMO.placeStore.setTrue(block);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == configInstance.getRepairAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) {
|
if (id == configInstance.getRepairAnvilId() && configInstance.getRepairAnvilMessagesEnabled()) {
|
||||||
@ -246,26 +207,6 @@ public class BlockListener implements Listener {
|
|||||||
if (BlockChecks.shouldBeWatched(block)) {
|
if (BlockChecks.shouldBeWatched(block)) {
|
||||||
mcMMO.placeStore.setFalse(block);
|
mcMMO.placeStore.setFalse(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove metadata from fallen sand/gravel
|
|
||||||
Material aboveType = block.getRelative(BlockFace.UP).getType();
|
|
||||||
|
|
||||||
if (aboveType == Material.SAND || aboveType == Material.GRAVEL) {
|
|
||||||
for (int y = 1; block.getY() + y <= block.getWorld().getMaxHeight(); y++) {
|
|
||||||
Block relative = block.getRelative(0, y, 0);
|
|
||||||
Material relativeType = relative.getType();
|
|
||||||
|
|
||||||
if ((relativeType == Material.SAND || relativeType == Material.GRAVEL) && mcMMO.placeStore.isTrue(relative)) {
|
|
||||||
mcMMO.placeStore.setFalse(relative);
|
|
||||||
}
|
|
||||||
else if (!BlockChecks.shouldBeWatched(relative) && mcMMO.placeStore.isTrue(relative)) {
|
|
||||||
mcMMO.placeStore.setFalse(relative);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.gmail.nossr50.listeners;
|
package com.gmail.nossr50.listeners;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.AnimalTamer;
|
import org.bukkit.entity.AnimalTamer;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
@ -15,6 +17,7 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
@ -50,6 +53,26 @@ public class EntityListener implements Listener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
|
||||||
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
|
if (entity instanceof FallingBlock) {
|
||||||
|
int entityID = entity.getEntityId();
|
||||||
|
Block block = event.getBlock();
|
||||||
|
|
||||||
|
if (mcMMO.placeStore.isTrue(block)) {
|
||||||
|
plugin.addToFallingBlockTracker(entityID, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.fallingBlockIsTracked(entityID) && block.getType() == Material.AIR) {
|
||||||
|
mcMMO.placeStore.setFalse(plugin.getSourceBlock(entityID));
|
||||||
|
mcMMO.placeStore.setTrue(block);
|
||||||
|
plugin.removeFromFallingBlockTracker(entityID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor EntityDamageByEntity events.
|
* Monitor EntityDamageByEntity events.
|
||||||
*
|
*
|
||||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
import net.shatteredlands.shatt.backup.ZipLibrary;
|
import net.shatteredlands.shatt.backup.ZipLibrary;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@ -96,6 +97,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
|
|
||||||
private HashMap<String, String> aliasMap = new HashMap<String, String>(); //Alias - Command
|
private HashMap<String, String> aliasMap = new HashMap<String, String>(); //Alias - Command
|
||||||
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
|
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
|
||||||
|
private HashMap<Integer, Block> fallingBlockTracker = new HashMap<Integer, Block>();
|
||||||
|
|
||||||
private static Database database;
|
private static Database database;
|
||||||
public static mcMMO p;
|
public static mcMMO p;
|
||||||
@ -519,6 +521,44 @@ public class mcMMO extends JavaPlugin {
|
|||||||
tntTracker.remove(tntID);
|
tntTracker.remove(tntID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an ID value to the FallingBlock tracker.
|
||||||
|
*
|
||||||
|
* @param fallingBlockID The EntityID of the FallingBlock
|
||||||
|
*/
|
||||||
|
public void addToFallingBlockTracker(int fallingBlockID, Block sourceBlock) {
|
||||||
|
fallingBlockTracker.put(fallingBlockID, sourceBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if a given FallingBlock Entity is tracked.
|
||||||
|
*
|
||||||
|
* @param tntID The EntityID of the FallingBlock
|
||||||
|
* @return true if the FallingBlock is being tracked, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean fallingBlockIsTracked(int fallingBlockID) {
|
||||||
|
return fallingBlockTracker.containsKey(fallingBlockID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the initial location of the FallingBlock.
|
||||||
|
*
|
||||||
|
* @param fallingBlockID The EntityID of the FallingBlock
|
||||||
|
* @return the Player who detonated it
|
||||||
|
*/
|
||||||
|
public Block getSourceBlock(int fallingBlockID) {
|
||||||
|
return fallingBlockTracker.get(fallingBlockID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove FallingBlock from the tracker after it lands.
|
||||||
|
*
|
||||||
|
* @param fallingBlockID The EntityID of the FallingBlock
|
||||||
|
*/
|
||||||
|
public void removeFromFallingBlockTracker(int fallingBlockID) {
|
||||||
|
fallingBlockTracker.remove(fallingBlockID);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getMainDirectory() {
|
public static String getMainDirectory() {
|
||||||
return mainDirectory;
|
return mainDirectory;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user