mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Metadata > Hashmap
This commit is contained in:
parent
fa645b5e00
commit
0f023f627c
@ -317,14 +317,15 @@ public class EntityListener implements Listener {
|
||||
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (entity instanceof TNTPrimed) {
|
||||
int id = entity.getEntityId();
|
||||
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||
|
||||
if (!plugin.tntIsTracked(id)) {
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
||||
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||
|
||||
if (miningManager.canUseBiggerBombs()) {
|
||||
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
||||
@ -341,21 +342,20 @@ public class EntityListener implements Listener {
|
||||
public void onEnitityExplode(EntityExplodeEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (entity instanceof TNTPrimed) {
|
||||
int id = entity.getEntityId();
|
||||
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||
// We can make this assumption because we (should) be the only ones using this exact metadata
|
||||
Player player = plugin.getServer().getPlayer(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());
|
||||
|
||||
if (!plugin.tntIsTracked(id)) {
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
||||
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||
|
||||
if (miningManager.canUseBlastMining()) {
|
||||
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
|
||||
event.setYield(0);
|
||||
}
|
||||
|
||||
plugin.removeFromTNTTracker(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.gmail.nossr50;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.shatteredlands.shatt.backup.ZipLibrary;
|
||||
@ -65,8 +64,6 @@ public class mcMMO extends JavaPlugin {
|
||||
private final SelfListener selfListener = new SelfListener();
|
||||
private final WorldListener worldListener = new WorldListener();
|
||||
|
||||
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
|
||||
|
||||
public static mcMMO p;
|
||||
|
||||
public static ChunkManager placeStore;
|
||||
@ -91,10 +88,12 @@ public class mcMMO extends JavaPlugin {
|
||||
private boolean xpEventEnabled = false;
|
||||
|
||||
// Metadata Values
|
||||
public static FixedMetadataValue metadataValue;
|
||||
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
|
||||
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
|
||||
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
|
||||
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
|
||||
public final static String furnaceMetadataKey = "mcMMO: Tracked Furnace";
|
||||
public final static String tntMetadataKey = "mcMMO: Tracked TNT";
|
||||
|
||||
public static FixedMetadataValue metadataValue;
|
||||
|
||||
/**
|
||||
* Things to be run when the plugin is enabled.
|
||||
@ -200,45 +199,6 @@ public class mcMMO extends JavaPlugin {
|
||||
getLogger().info("Was disabled."); // How informative!
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set of values to the TNT tracker.
|
||||
*
|
||||
* @param tntID The EntityID of the TNT
|
||||
* @param playerName The name of the detonating player
|
||||
*/
|
||||
public void addToTNTTracker(int tntID, String playerName) {
|
||||
tntTracker.put(tntID, playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if a given TNT Entity is tracked.
|
||||
*
|
||||
* @param tntID The EntityID of the TNT
|
||||
* @return true if the TNT is being tracked, false otherwise
|
||||
*/
|
||||
public boolean tntIsTracked(int tntID) {
|
||||
return tntTracker.containsKey(tntID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player who detonated the TNT.
|
||||
*
|
||||
* @param tntID The EntityID of the TNT
|
||||
* @return the Player who detonated it
|
||||
*/
|
||||
public Player getTNTPlayer(int tntID) {
|
||||
return getServer().getPlayer(tntTracker.get(tntID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove TNT from the tracker after it explodes.
|
||||
*
|
||||
* @param tntID The EntityID of the TNT
|
||||
*/
|
||||
public void removeFromTNTTracker(int tntID) {
|
||||
tntTracker.remove(tntID);
|
||||
}
|
||||
|
||||
public static String getMainDirectory() {
|
||||
return mainDirectory;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.block.BlockState;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
@ -100,7 +101,7 @@ public class MiningManager extends SkillManager{
|
||||
SkillUtils.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
|
||||
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
|
||||
|
||||
mcMMO.p.addToTNTTracker(tnt.getEntityId(), player.getName());
|
||||
tnt.setMetadata(mcMMO.tntMetadataKey, new FixedMetadataValue(mcMMO.p, player.getName()));
|
||||
tnt.setFuseTicks(0);
|
||||
targetBlock.setData((byte) 0x0);
|
||||
targetBlock.setType(Material.AIR);
|
||||
|
Loading…
Reference in New Issue
Block a user