mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36: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) {
|
public void onExplosionPrime(ExplosionPrimeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity instanceof TNTPrimed) {
|
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||||
int id = entity.getEntityId();
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||||
|
|
||||||
if (miningManager.canUseBiggerBombs()) {
|
if (miningManager.canUseBiggerBombs()) {
|
||||||
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
||||||
@ -341,21 +342,20 @@ public class EntityListener implements Listener {
|
|||||||
public void onEnitityExplode(EntityExplodeEvent event) {
|
public void onEnitityExplode(EntityExplodeEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
||||||
if (entity instanceof TNTPrimed) {
|
if (entity instanceof TNTPrimed && entity.hasMetadata(mcMMO.tntMetadataKey)) {
|
||||||
int id = entity.getEntityId();
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();
|
||||||
|
|
||||||
if (miningManager.canUseBlastMining()) {
|
if (miningManager.canUseBlastMining()) {
|
||||||
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
|
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
|
||||||
event.setYield(0);
|
event.setYield(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.removeFromTNTTracker(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package com.gmail.nossr50;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.shatteredlands.shatt.backup.ZipLibrary;
|
import net.shatteredlands.shatt.backup.ZipLibrary;
|
||||||
@ -65,8 +64,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
private final SelfListener selfListener = new SelfListener();
|
private final SelfListener selfListener = new SelfListener();
|
||||||
private final WorldListener worldListener = new WorldListener();
|
private final WorldListener worldListener = new WorldListener();
|
||||||
|
|
||||||
private HashMap<Integer, String> tntTracker = new HashMap<Integer, String>();
|
|
||||||
|
|
||||||
public static mcMMO p;
|
public static mcMMO p;
|
||||||
|
|
||||||
public static ChunkManager placeStore;
|
public static ChunkManager placeStore;
|
||||||
@ -91,10 +88,12 @@ public class mcMMO extends JavaPlugin {
|
|||||||
private boolean xpEventEnabled = false;
|
private boolean xpEventEnabled = false;
|
||||||
|
|
||||||
// Metadata Values
|
// Metadata Values
|
||||||
public static FixedMetadataValue metadataValue;
|
|
||||||
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
|
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
|
||||||
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
|
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
|
||||||
public final static String furnaceMetadataKey = "mcMMO: Tracked Furnace";
|
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.
|
* Things to be run when the plugin is enabled.
|
||||||
@ -200,45 +199,6 @@ public class mcMMO extends JavaPlugin {
|
|||||||
getLogger().info("Was disabled."); // How informative!
|
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() {
|
public static String getMainDirectory() {
|
||||||
return mainDirectory;
|
return mainDirectory;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.block.BlockState;
|
|||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
@ -100,7 +101,7 @@ public class MiningManager extends SkillManager{
|
|||||||
SkillUtils.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
|
SkillUtils.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
|
||||||
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
|
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);
|
tnt.setFuseTicks(0);
|
||||||
targetBlock.setData((byte) 0x0);
|
targetBlock.setData((byte) 0x0);
|
||||||
targetBlock.setType(Material.AIR);
|
targetBlock.setType(Material.AIR);
|
||||||
|
Loading…
Reference in New Issue
Block a user