Skip to content
Permalink
Browse files

Add /sentinel enemydrops, fixes #20

  • Loading branch information...
mcmonkey4eva committed Apr 23, 2016
1 parent f20e2a3 commit 7231f771dabce6bf06ee4efca8cc44e963aa7da0
@@ -57,6 +57,7 @@ Created by mcmonkey4eva on behalf of the Citizens and Denizen teams.
- /sentinel drops - Changes the drops of the current NPC.
- /sentinel spawnpoint - Changes the NPC's spawn point to its current location, or removes it if it's already there.
- /sentinel forgive - Forgives all current targets.
- /sentinel enemydrops - Toggles whether enemy mobs of this NPC drop items.
- /sentinel info - Shows info on the current NPC.
- /sentinel stats - Shows statistics about the current NPC.
- /sentinel targets - Shows the targets of the current NPC.
@@ -636,6 +636,16 @@ else if (arg0.equals("forgive") && sender.hasPermission("sentinel.forgive")) {
sender.sendMessage(prefixGood + "Targets forgiven.");
return true;
}
else if (arg0.equals("enemydrops") && sender.hasPermission("sentinel.enemydrops")) {
sentinel.enemyDrops = !sentinel.enemyDrops;
if (sentinel.enemyDrops) {
sender.sendMessage(prefixGood + "NPC enemy mobs now drop items and XP!");
}
else {
sender.sendMessage(prefixGood + "NPC enemy mobs no longer drop items and XP!");
}
return true;
}
else if (arg0.equals("targets") && sender.hasPermission("sentinel.info")) {
sender.sendMessage(prefixGood + ChatColor.RESET + sentinel.getNPC().getFullName() + ColorBasic
+ ": owned by " + ChatColor.RESET + getOwner(sentinel.getNPC()));
@@ -711,6 +721,7 @@ else if (arg0.equals("stats") && sender.hasPermission("sentinel.info")) {
if (sender.hasPermission("sentinel.drops")) sender.sendMessage(prefixGood + "/sentinel drops - Changes the drops of the current NPC.");
if (sender.hasPermission("sentinel.spawnpoint")) sender.sendMessage(prefixGood + "/sentinel spawnpoint - Changes the NPC's spawn point to its current location, or removes it if it's already there.");
if (sender.hasPermission("sentinel.forgive")) sender.sendMessage(prefixGood + "/sentinel forgive - Forgives all current targets.");
if (sender.hasPermission("sentinel.enemydrops")) sender.sendMessage(prefixGood + "/sentinel enemydrops - Toggles whether enemy mobs of this NPC drop items.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel info - Shows info on the current NPC.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel targets - Shows the targets of the current NPC.");
if (sender.hasPermission("sentinel.info")) sender.sendMessage(prefixGood + "/sentinel stats - Shows statistics about the current NPC.");
@@ -157,6 +157,9 @@ public SentinelTrait() {
@Persist("drops")
public List<ItemStack> drops = new ArrayList<ItemStack>();

@Persist("enemyDrops")
public boolean enemyDrops = false;

public UUID getGuarding() {
if (guardingLower == 0 && guardingUpper == 0) {
return null;
@@ -195,7 +198,7 @@ public void whenAttacksAreHappening(EntityDamageByEntityEvent event) {
}
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR)
public void whenAttacksHappened(EntityDamageByEntityEvent event) {
if (!npc.isSpawned()) {
return;
@@ -223,6 +226,9 @@ else if (event.getDamager() instanceof Projectile) {
return;
}
stats_damageGiven += event.getFinalDamage();
if (!enemyDrops) {
needsDropsClear.put(event.getEntity().getUniqueId(), true);
}
return;
}
Entity e = event.getDamager();
@@ -237,6 +243,9 @@ else if (event.getDamager() instanceof Projectile) {
return;
}
stats_damageGiven += event.getFinalDamage();
if (!enemyDrops) {
needsDropsClear.put(event.getEntity().getUniqueId(), true);
}
return;
}
}
@@ -287,6 +296,7 @@ public void onAttach() {
fightback = config.getBoolean("sentinel defaults.fightback", true);
needsAmmo = config.getBoolean("sentinel defaults.needs ammo", false);
safeShot = config.getBoolean("sentinel defaults.safe shot", true);
enemyDrops = config.getBoolean("sentinel defaults.enemy drops", false);
ignores.add(SentinelTarget.OWNER);
}

@@ -515,6 +525,9 @@ public void punch(LivingEntity entity) {
relative.setY(0.75);
relative.multiply(0.5);
entity.setVelocity(entity.getVelocity().add(relative));
if (!enemyDrops) {
needsDropsClear.put(entity.getUniqueId(), true);
}
}
else {
entity.damage(getDamage(), getLivingEntity());
@@ -1061,19 +1074,33 @@ public void onSpawn() {
}
}

@EventHandler
public void whenSomethingDies(EntityDeathEvent event) {
if (!CitizensAPI.getNPCRegistry().isNPC(event.getEntity())
|| !CitizensAPI.getNPCRegistry().getNPC(event.getEntity()).getUniqueId().equals(npc.getUniqueId())) {
return;
public HashMap<UUID, Boolean> needsDropsClear = new HashMap<UUID, Boolean>();

@EventHandler(priority = EventPriority.HIGHEST)
public void whenSomethingMightDie(EntityDamageByEntityEvent event) {
needsDropsClear.remove(event.getEntity().getUniqueId());
}

@EventHandler(priority = EventPriority.MONITOR)
public void whenWeDie(EntityDeathEvent event) {
if (CitizensAPI.getNPCRegistry().isNPC(event.getEntity())
&& CitizensAPI.getNPCRegistry().getNPC(event.getEntity()).getUniqueId().equals(npc.getUniqueId())) {
event.getDrops().clear();
event.getDrops().addAll(drops);
event.setDroppedExp(0);
onDeath();
}
onDeath(event.getEntity().getLocation());
}

public void onDeath(Location spot) {
for (ItemStack item: drops) {
spot.getWorld().dropItemNaturally(spot, item.clone());
@EventHandler(priority = EventPriority.LOW)
public void whenSomethingDies(EntityDeathEvent event) {
if (needsDropsClear.containsKey(event.getEntity().getUniqueId())) {
event.getDrops().clear();
event.setDroppedExp(0);
}
}

public void onDeath() {
if (respawnTime < 0) {
BukkitRunnable removeMe = new BukkitRunnable() {
@Override
@@ -22,10 +22,12 @@ sentinel defaults:
fightback: true
# Whether this NPC needs ammo to fight with.
needs ammo: false
# Whether the NPC will avoiding damaging non-targets.
# Whether this NPC will avoid damaging non-targets.
safe shot: true
# Default respawn time, in ticks.
respawn time: 100
# Whether enemy mobs killed by this NPC should drop items.
enemy drops: false

random:
# What sound to play when the "spectral" attack is used.
@@ -60,6 +60,8 @@ permissions:
sentinel.spawnpoint: true
# /sentinel forgive
sentinel.forgive: true
# /sentinel enemydrops
sentinel.enemydrops: true
# /sentinel info, /sentinel targets, /sentinel stats
sentinel.info: true
# Edit other people's NPCs

0 comments on commit 7231f77

Please sign in to comment.
You can’t perform that action at this time.