Skip to content

Commit

Permalink
Added a way to disable the head drop on death.
Browse files Browse the repository at this point in the history
You can disable the drop completly, or enable it only if the player was killed by another player.

Also: restructuration of the config file.
  • Loading branch information
AmauryCarrade committed Jul 23, 2014
1 parent 4a08027 commit 5e080e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ C'est très la source.
- **Gameplay tweaks** (all optional, see configuration file)
- The golden melon is crafted using a gold block instead of eight gold nuggets.
![Craft golden melon](http://amaury.carrade.eu/files/Minecraft/Plugins/UH/UHPlugin_Craft_GlisteringMelon.png)
- When a player die, his head is dropped; this head can be used to craft a golden apple.
- When a player die, his head is dropped (pvp-only flag available); this head can be used to craft a golden apple.
- The craft is the same as the normal golden apple, with a head instead of an apple.
![Craft golden Apple from human](http://amaury.carrade.eu/files/Minecraft/Plugins/UH/UHPlugin_Craft_GoldenAppleFromHuman.png)
- You can configure the number of apples crafted, the type (normal or Notch apple), and if a lore is added (saying “Made from the fallen head of *ThePlayer*”).
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/me/azenet/UHPlugin/UHPluginListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,36 @@ public void onPlayerDeath(final PlayerDeathEvent ev) {
this.p.getGameManager().addDead(ev.getEntity().getName());

// Kicks the player if needed.
if (this.p.getConfig().getBoolean("kick-on-death.kick", true)) {
if (this.p.getConfig().getBoolean("death.kick.do", true)) {
Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() {

@Override
public void run() {
ev.getEntity().kickPlayer("jayjay");
}
}, 20L*this.p.getConfig().getInt("kick-on-death.time", 30));
}, 20L*this.p.getConfig().getInt("death.kick.time", 30));
}

// Drops the skull of the player.
Location l = ev.getEntity().getLocation();
try {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
skullMeta.setOwner(((Player)ev.getEntity()).getName());
skullMeta.setDisplayName(ChatColor.RESET + ((Player)ev.getEntity()).getName());
skull.setItemMeta(skullMeta);
l.getWorld().dropItem(l, skull);
} catch (Exception e) {
e.printStackTrace();
if(p.getConfig().getBoolean("death.head.drop")) {
if(!p.getConfig().getBoolean("death.head.pvpOnly")
|| (p.getConfig().getBoolean("death.head.pvpOnly") && ev.getEntity().getKiller() != null && ev.getEntity().getKiller() instanceof Player)) {
Location l = ev.getEntity().getLocation();
try {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
skullMeta.setOwner(((Player)ev.getEntity()).getName());
skullMeta.setDisplayName(ChatColor.RESET + ((Player)ev.getEntity()).getName());
skull.setItemMeta(skullMeta);
l.getWorld().dropItem(l, skull);
} catch (Exception e) {
e.printStackTrace();
}
}
}

// Sends a team-death message if needed.
if(p.getConfig().getBoolean("death-messages.notifyIfTeamHasFallen", false)) {
if(p.getConfig().getBoolean("death.messages.notifyIfTeamHasFallen", false)) {
UHTeam team = p.getTeamManager().getTeamForPlayer((Player) ev.getEntity());
if(team != null) {
boolean isAliveTeam = false;
Expand All @@ -123,12 +128,12 @@ public void run() {
}

if(!isAliveTeam) {
p.getServer().broadcastMessage(p.getConfig().getString("death-messages.teamDeathMessagesPrefix", "") + "The team " + ChatColor.RESET + team.getChatColor() + team.getDisplayName() + ChatColor.RESET + p.getConfig().getString("death-messages.teamDeathMessagesPrefix", "") + " has fallen!");
p.getServer().broadcastMessage(p.getConfig().getString("death.messages.teamDeathMessagesPrefix", "") + "The team " + ChatColor.RESET + team.getChatColor() + team.getDisplayName() + ChatColor.RESET + p.getConfig().getString("death.messages.teamDeathMessagesPrefix", "") + " has fallen!");
}
}
}

ev.setDeathMessage(p.getConfig().getString("death-messages.deathMessagesPrefix", "") + ev.getDeathMessage());
ev.setDeathMessage(p.getConfig().getString("death.messages.deathMessagesPrefix", "") + ev.getDeathMessage());

// Updates the number of alive players/teams
p.getGameManager().updateAliveCounters();
Expand Down Expand Up @@ -161,7 +166,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent ev) {
*/
@EventHandler
public void onPlayerLogin(PlayerLoginEvent ev) {
if (this.p.getGameManager().isPlayerDead(ev.getPlayer().getName()) && !this.p.getConfig().getBoolean("kick-on-death.allow-reconnect", true)) {
if (this.p.getGameManager().isPlayerDead(ev.getPlayer().getName()) && !this.p.getConfig().getBoolean("death.kick.allow-reconnect", true)) {
ev.setResult(Result.KICK_OTHER);
ev.setKickMessage("Vous êtes mort !");
}
Expand Down
21 changes: 12 additions & 9 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ daylightCycle:
# The title of the scoreboard
scoreboard: Kill the Patrick

kick-on-death:
kick: true
time: 30
allow-reconnect: true

death-messages:
notifyIfTeamHasFallen: true
deathMessagesPrefix: "§6" # Use this to increase visibility of death messages.
teamDeathMessagesPrefix: "§6"
death:
messages:
notifyIfTeamHasFallen: true
deathMessagesPrefix: "§6" # Use this to increase visibility of death messages.
teamDeathMessagesPrefix: "§6"
kick:
do: true
time: 30
allow-reconnect: true
head:
drop: true
pvpOnly: false

# If true, the name of the players will be colorized according to the teams.
colorizeChat: true
Expand Down

0 comments on commit 5e080e8

Please sign in to comment.