Skip to content

Commit 88566ee

Browse files
authored
version 1.2 (#18)
* Removed "compatibility" code * Fix #17 * default flying speed is 0.1f, not 0.2f (0.2f is default walking speed)
1 parent d5ff048 commit 88566ee

File tree

4 files changed

+36
-71
lines changed

4 files changed

+36
-71
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>to.us.tf</groupId>
88
<artifactId>DeathSpectating</artifactId>
9-
<version>1.1.3</version>
9+
<version>1.2</version>
1010
<properties>
1111
<maven.compiler.source>1.8</maven.compiler.source>
1212
<maven.compiler.target>1.8</maven.compiler.target>

src/main/java/to/us/tf/DeathSpectating/CompatUtil.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/java/to/us/tf/DeathSpectating/DeathSpectating.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import org.bukkit.Location;
66
import org.bukkit.Material;
77
import org.bukkit.Particle;
8+
import org.bukkit.Sound;
9+
import org.bukkit.SoundCategory;
810
import org.bukkit.Statistic;
9-
import org.bukkit.World;
1011
import org.bukkit.enchantments.Enchantment;
11-
import org.bukkit.entity.Creature;
1212
import org.bukkit.entity.Entity;
1313
import org.bukkit.entity.EntityType;
1414
import org.bukkit.entity.ExperienceOrb;
@@ -24,15 +24,16 @@
2424
import org.bukkit.metadata.FixedMetadataValue;
2525
import org.bukkit.plugin.java.JavaPlugin;
2626
import org.bukkit.potion.PotionEffect;
27-
import org.bukkit.scheduler.BukkitRunnable;
2827
import to.us.tf.DeathSpectating.events.DeathSpectatingEvent;
2928
import to.us.tf.DeathSpectating.features.Titles;
3029
import to.us.tf.DeathSpectating.listeners.DamageListener;
3130
import to.us.tf.DeathSpectating.listeners.MiscListeners;
3231
import to.us.tf.DeathSpectating.tasks.SpectateTask;
3332

3433
import java.util.ArrayList;
34+
import java.util.HashSet;
3535
import java.util.List;
36+
import java.util.Set;
3637
import java.util.logging.Level;
3738

3839
/**
@@ -49,8 +50,7 @@ public void onEnable()
4950
getServer().getPluginManager().registerEvents(this, this);
5051
getServer().getPluginManager().registerEvents(new DamageListener(this), this);
5152
getServer().getPluginManager().registerEvents(new MiscListeners(this), this);
52-
if (!CompatUtil.isOlder(11)) //TODO: register in class, not in main(?)
53-
getServer().getPluginManager().registerEvents(new Titles(this, configManager), this);
53+
getServer().getPluginManager().registerEvents(new Titles(this, configManager), this);
5454
}
5555

5656
public ConfigManager getConfigManager()
@@ -82,7 +82,7 @@ public void setSpectating(Player player, boolean spectate, GameMode gameMode)
8282
player.removeMetadata("DEAD", this);
8383
player.setLastDamageCause(null);
8484
player.setGameMode(getServer().getDefaultGameMode());
85-
player.setFlySpeed(0.2f);
85+
player.setFlySpeed(0.1f);
8686
}
8787
}
8888

@@ -144,9 +144,10 @@ public boolean startDeathSpectating(Player player)
144144
{
145145
/*Set spectating attributes*/
146146
//Player#isDead() == true when PlayerDeathEvent is fired.
147+
//Also prevents any potential to pickup anything that's dropped.
147148
setSpectating(player, true, player.getGameMode());
148149

149-
/*Start Death simulation*/
150+
/*Start Death Event simulation*/
150151

151152
boolean keepInventory = Boolean.valueOf(player.getWorld().getGameRuleValue("keepInventory"));
152153
boolean showDeathMessages = Boolean.valueOf(player.getWorld().getGameRuleValue("showDeathMessages"));
@@ -171,17 +172,18 @@ public boolean startDeathSpectating(Player player)
171172
//TODO: Non-vanilla behavior, see issue #4
172173
String deathMessage = "";
173174

174-
/*Fire PlayerDeathEvent*/
175+
/*Prepare PlayerDeathEvent*/
175176
PlayerDeathEvent deathEvent = new PlayerDeathEvent(player, itemsToDrop, expToDrop, deathMessage);
176177
deathEvent.setKeepInventory(keepInventory); //CB's constructor does indeed set whether the inventory is kept or not, using the gamerule's value
178+
//And fire
177179
getServer().getPluginManager().callEvent(deathEvent);
178180

179181
//TODO: Non-vanilla behavior, see issue #5
180182
//Print death message
181183
if (deathEvent.getDeathMessage() != null && !deathEvent.getDeathMessage().isEmpty() && showDeathMessages)
182184
getServer().broadcastMessage(deathEvent.getDeathMessage());
183185

184-
//Clear and drop items
186+
//Clear and drop items if keepInventory == false
185187
if (!deathEvent.getKeepInventory())
186188
{
187189
player.getInventory().clear();
@@ -212,14 +214,22 @@ public boolean startDeathSpectating(Player player)
212214
player.incrementStatistic(Statistic.DEATHS);
213215
player.setStatistic(Statistic.TIME_SINCE_DEATH, 0);
214216

217+
//Clear potion effects TODO: do this before firing death event?
218+
for (PotionEffect potionEffect : player.getActivePotionEffects())
219+
player.removePotionEffect(potionEffect.getType());
220+
215221
//TODO: Non-vanilla behavior: Player death animation (red and falling over) (Issue #13)
216222
//Smoke effect //TODO: after 20 ticks (Issue #14) (Will implement 20 tick delay after issue #13 is resolved
217223
if (isSpectating(player)) //TODO: does smoke effect/death animation occur if player#spigot()#respawn() is called on death? My guess is no.
218-
player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation(), 25);
219-
220-
//Clear potion effects
221-
for (PotionEffect potionEffect : player.getActivePotionEffects())
222-
player.removePotionEffect(potionEffect.getType());
224+
player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation(), 25, 1, 0.5, 1, 0.001);
225+
226+
//Play the "death" sound (to all other players except the killed player; vanilla (spigot?) behavior).
227+
//fyi, default resource pack doesn't have a different sound for this; only custom resource packs make use of this.
228+
//TODO: distance check?
229+
Set<Player> players = new HashSet<>(player.getWorld().getPlayers());
230+
players.remove(player);
231+
for (Player p : players)
232+
p.playSound(player.getLocation(), Sound.ENTITY_PLAYER_DEATH, SoundCategory.PLAYERS, 1.0f, 1.0f);
223233

224234
/* End Death simulation*/
225235

src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package to.us.tf.DeathSpectating.listeners;
22

33
import org.bukkit.Material;
4+
import org.bukkit.Sound;
5+
import org.bukkit.SoundCategory;
46
import org.bukkit.entity.EntityType;
57
import org.bukkit.entity.Player;
68
import org.bukkit.event.EventHandler;
79
import org.bukkit.event.EventPriority;
810
import org.bukkit.event.Listener;
911
import org.bukkit.event.entity.EntityDamageEvent;
10-
import org.bukkit.inventory.Inventory;
1112
import org.bukkit.inventory.PlayerInventory;
12-
import to.us.tf.DeathSpectating.CompatUtil;
1313
import to.us.tf.DeathSpectating.DeathSpectating;
1414

1515
/**
@@ -42,15 +42,8 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event)
4242

4343
//Ignore if player is holding a totem of undying
4444
PlayerInventory inventory = player.getInventory();
45-
try
46-
{
47-
if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM)
48-
return;
49-
}
50-
catch (NoSuchFieldError | NoSuchMethodError e) //TOTEM (not in 1.10 and below) //getItemInMainHand, etc. (not in 1.8 and below)
51-
{
52-
if (CompatUtil.isNewer()) throw e;
53-
}
45+
if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM)
46+
return;
5447

5548
//Ignore if this is probably the result of the Essentials suicide command
5649
//Essentials will perform Player#setHealth(0), which does not fire a damage event, but does kill the player. This will lead to a double death message.
@@ -59,11 +52,17 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event)
5952
return;
6053

6154
player.setLastDamageCause(event);
62-
//TODO: fire EntityResurrectEvent
55+
//TODO: fire EntityResurrectEvent(?)
6356

6457
/*Put player in death spectating mode*/
6558
if (instance.startDeathSpectating(player))
59+
{
6660
//Cancel event so player doesn't actually die
6761
event.setCancelled(true);
62+
63+
//Play the "hit" sound (since we canceled the event, the hit sound will not play)
64+
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT, SoundCategory.PLAYERS, 1.0f, 1.0f);
65+
}
66+
6867
}
6968
}

0 commit comments

Comments
 (0)