Skip to content
Browse files

Metadata > Hashmap

  • Loading branch information...
1 parent fa645b5 commit 0f023f627c7e84fe85db8032f0c4d9d158eb5c87 @gmcferrin gmcferrin committed Apr 2, 2013
View
20 src/main/java/com/gmail/nossr50/listeners/EntityListener.java
@@ -317,14 +317,15 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
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 void onExplosionPrime(ExplosionPrimeEvent event) {
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);
}
}
View
50 src/main/java/com/gmail/nossr50/mcMMO.java
@@ -3,7 +3,6 @@
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 @@
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 @@
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 void onDisable() {
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;
}
View
3 src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java
@@ -10,6 +10,7 @@
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 void remoteDetonation() {
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);

0 comments on commit 0f023f6

Please sign in to comment.
Something went wrong with that request. Please try again.