From c76b725052bd4a2073b15523c367a9fa477e4934 Mon Sep 17 00:00:00 2001 From: Nathan Blaney Date: Sun, 23 Jun 2024 19:59:02 +1000 Subject: [PATCH] Updated: Extra death causes added Config has been adjusted, and the /kill command now support death cause --- docs/commands/kill.md | 2 +- .../royaldev/royalcommands/death/Death.java | 70 +++++--- .../royalcommands/rcommands/CmdKill.java | 28 ++- .../src/main/resources/deathmessages.yml | 170 ++++++++++-------- .../src/main/resources/plugin.yml | 2 +- 5 files changed, 167 insertions(+), 105 deletions(-) diff --git a/docs/commands/kill.md b/docs/commands/kill.md index ac86fa86..30bc3064 100644 --- a/docs/commands/kill.md +++ b/docs/commands/kill.md @@ -11,7 +11,7 @@ command: supports: name-completion: false time-format: false - usage: /kill [player] + usage: /kill [player] (cause) layout: command title: /kill --- diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/death/Death.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/death/Death.java index 9f8b9871..02452856 100644 --- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/death/Death.java +++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/death/Death.java @@ -44,15 +44,24 @@ private String getMessageType() { case BLOCK_EXPLOSION: pullFrom = "blo"; break; + case CAMPFIRE: + pullFrom = "cam"; + break; case CONTACT: pullFrom = "con"; break; + case CUSTOM: + case DRAGON_BREATH: + pullFrom = "dra"; + break; + case DROWNING: + pullFrom = "dro"; + break; case ENTITY_ATTACK: - case PROJECTILE: - pullFrom = (this.getDeathType() == DeathType.PLAYER) ? "pvp" : "mob"; + pullFrom = "mob"; break; - case SUFFOCATION: - pullFrom = "suf"; + case ENTITY_EXPLOSION: + pullFrom = "cre"; break; case FALL: pullFrom = "fal"; @@ -66,53 +75,58 @@ private String getMessageType() { case FIRE_TICK: pullFrom = "fir"; break; - case LAVA: - pullFrom = "lav"; + case FLY_INTO_WALL: + pullFrom = "fiw"; break; - case DROWNING: - pullFrom = "dro"; + case FREEZE: + pullFrom = "fro"; break; - case ENTITY_EXPLOSION: - pullFrom = "cre"; + case HOT_FLOOR: + pullFrom = "hot"; break; - case VOID: - pullFrom = "voi"; + case LAVA: + pullFrom = "lav"; break; case LIGHTNING: pullFrom = "lig"; break; - case SUICIDE: - pullFrom = "sui"; - break; - case STARVATION: - pullFrom = "sta"; + case MAGIC: + pullFrom = "mag"; break; + case MELTING: case POISON: pullFrom = "poi"; break; - case MAGIC: - pullFrom = "mag"; + case PROJECTILE: + pullFrom = (this.getDeathType() == DeathType.PLAYER) ? "pvp" : "mob"; break; - case WITHER: - pullFrom = "wit"; + case SONIC_BOOM: + pullFrom = "son"; + break; + case STARVATION: + pullFrom = "sta"; + break; + case SUFFOCATION: + pullFrom = "suf"; + break; + case SUICIDE: + pullFrom = "sui"; break; case THORNS: pullFrom = "tho"; break; - case DRAGON_BREATH: - pullFrom = "dra"; + case WITHER: + pullFrom = "wit"; break; - case FREEZE: - pullFrom = "fro"; + case VOID: + pullFrom = "voi"; break; - case MELTING: - case CUSTOM: default: pullFrom = "oth"; break; } return pullFrom; - } + }//A B C D E F G H I J K L M N O P Q R S T U V W X y Z private RoyalCommands getPlugin() { return this.plugin; diff --git a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdKill.java b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdKill.java index 0fa2810b..ae4a8868 100644 --- a/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdKill.java +++ b/modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdKill.java @@ -8,15 +8,30 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.royaldev.royalcommands.AuthorizationHandler.PermType; import org.royaldev.royalcommands.MessageColor; import org.royaldev.royalcommands.RoyalCommands; +import java.util.ArrayList; +import java.util.List; + @ReflectCommand public class CmdKill extends TabCommand { public CmdKill(final RoyalCommands instance, final String name) { - super(instance, name, true, new Short[]{CompletionType.ONLINE_PLAYER.getShort()}); + super(instance, name, true, new Short[]{CompletionType.ONLINE_PLAYER.getShort(), CompletionType.CUSTOM.getShort()}); + } + + @Override + protected List getCustomCompletions(final CommandSender cs, final Command cmd, final String label, final String[] args, final String arg) { + ArrayList causes = new ArrayList<>(); + for (EntityDamageEvent.DamageCause cause : EntityDamageEvent.DamageCause.values()) { + if (!cause.name().toLowerCase().startsWith(arg.toLowerCase())) continue; + causes.add(cause.name().toLowerCase()); + } + return causes; } @Override @@ -34,6 +49,17 @@ public boolean runCommand(final CommandSender cs, final Command cmd, final Strin cs.sendMessage(MessageColor.NEGATIVE + "You cannot kill that player!"); return true; } + if (args.length > 1){ + Player p = (Player) cs; + try{ + EntityDamageEvent.DamageCause cause = EntityDamageEvent.DamageCause.valueOf(args[1].toUpperCase()); + t.setLastDamageCause(new EntityDamageByEntityEvent(p, t, cause, 0D)); + } catch (IllegalArgumentException e) { + cs.sendMessage(MessageColor.NEGATIVE + "Please use a valid cause of death."); + return true; + } + + } t.setHealth(0); cs.sendMessage(MessageColor.POSITIVE + "You have killed " + MessageColor.NEUTRAL + t.getDisplayName() + MessageColor.POSITIVE + "."); return true; diff --git a/modules/RoyalCommands/src/main/resources/deathmessages.yml b/modules/RoyalCommands/src/main/resources/deathmessages.yml index eda429ca..9551b730 100644 --- a/modules/RoyalCommands/src/main/resources/deathmessages.yml +++ b/modules/RoyalCommands/src/main/resources/deathmessages.yml @@ -24,118 +24,140 @@ var_color: DARK_AQUA mes_color: RED ################### -# Sections! -# pvp <- For player vs player combat death messages -# lav <- Lava deaths -# fir <- Fire deaths -# dro <- Drowning deaths -# con <- Contact deaths (cacti) -# sta <- Starvation deaths -# sui <- Suicide deaths -# poi <- Poison deaths -# lig <- Lightning deaths -# fal <- Fall deaths -# fab <- Falling block deaths -# blo <- Block explosion deaths -# cre <- Creeper explosion deaths -# suf <- Suffocation deaths -# voi <- Void deaths -# mag <- Magic deaths (harming potions, etc) -# mob <- Monster death messages -# wit <- Wither death messages -# tho <- Thorns death messages -# oth <- Other death messages (unknown) +# Death Causes ################### -pvp: - - "{player} was killed by {killer} wielding {hand}." - - "{player} was struck down by {killer} with {hand}." - - "{killer} bashed {player} to a pulp with {hand}." - -lav: - - "{player} tried to swim in lava." - - "{player} is now obsidian." - - "{player} mistook lava for water." - -fir: - - "{player} was burnt to a crisp." - - "{player} caught on fire." - - "{player} was burned alive." +# blo <- Block explosion deaths +blo: + - "{player} exploded." + - "{player} has an explosive personality." + - "{player} is now scattered around the floor in chunks." -dro: - - "{player} is now one with the sea." - - "{player} is swimming with the fishies." - - "{player} tried to be a fish." +# cam <- Campfire deaths +cam: + - "{player} walked into the campfire." + - "{player} dropped a marshmallow into the campfire." +# con <- Contact deaths (cacti) con: - "{player} hugged a cactus." - "{player} forgot that cacti are sharp." -sta: - - "{player} forgot to eat." - - "Starvation took {player} from us." - -sui: - - "{player} committed suicide." +# cre <- Creeper explosion deaths +cre: + - "{player} hugged a creeper." + - "{player} got too close to a lil' creeper." -poi: - - "{player} has died from poison!" - - "{player} was poisoned!" +# dra <- Dragon Breath deaths +dra: + - "{player} took on the dragon and didn't survive to tell the story" -lig: - - "{player} was smitten by Zeus." - - "{player} was struck by lightning." +# dro <- Drowning deaths +dro: + - "{player} is now one with the sea." + - "{player} is swimming with the fishies." + - "{player} tried to be a fish." +# fal <- Fall deaths fal: - "{player} fell off a plateau." - "{player} fell off a cliff." - "{player} hit the ground too hard." - "{player} tried to fly." +# fab <- Falling block deaths fab: - "A block fell on {player}." - "A block fell on {player}, crushing his hopes and dreams." - "{player} got squished." -blo: - - "{player} exploded." - - "{player} has an explosive personality." - - "{player} is now scattered around the floor in chunks." +# fir <- Fire deaths +fir: + - "{player} was burnt to a crisp." + - "{player} caught on fire." + - "{player} was burned alive." -cre: - - "{player} hugged a creeper." - - "{player} got too close to a lil' creeper." +# fiw <- Flying into wall deaths +fiw: + - "{player} flew into a wall." + - "{player} hit the wall at warp speed." -suf: - - "{player} got caught in a block." - - "{player} suffocated." +# fro <- Frozen deaths +fro: + - "{player} froze because they couldn't let it go" -voi: - - "{player} fell into the void." - - "{player} fell out of the world." - - "{player} went past the space-time continuum." +# hot <- Magma touch deaths +hot: + - "Someone didn't tell {player} that the floor is lava." + +# lav <- Lava deaths +lav: + - "{player} tried to swim in lava." + - "{player} is now obsidian." + - "{player} mistook lava for water." + +# lig <- Lightning deaths +lig: + - "{player} was smitten by Zeus." + - "{player} was struck by lightning." +# mag <- Magic deaths (harming potions, etc) mag: - "{player} got hit by a nasty potion." +# mob <- Monster death messages mob: - "{player} was killed by a {mob}." - "{player} was attacked by {mob}." - "An angry {mob} killed {player}." -wit: - - "{player} was killed by a wither!" - - "A wither annihilated {player}." +# oth <- Other death messages (unknown) +oth: + - "{player} died of unknown causes." + +# poi <- Poison deaths +poi: + - "{player} has died from poison!" + - "{player} was poisoned!" +# pvp <- For player vs player combat death messages +pvp: + - "{player} was killed by {killer} wielding {hand}." + - "{player} was struck down by {killer} with {hand}." + - "{killer} bashed {player} to a pulp with {hand}." + +# sta <- Starvation deaths +sta: + - "{player} forgot to eat." + - "Starvation took {player} from us." + +# son <- Warden sonic boom deaths +son: + - "{player} couldn't handle the boom." + - "{player} ear drums popped." + +# sui <- Suicide deaths +sui: + - "{player} committed suicide." + +# suf <- Suffocation deaths +suf: + - "{player} got caught in a block." + - "{player} suffocated." + +# tho <- Thorns death messages tho: - "{player} got a taste of his own medicine." - "Reflected damage got the jump on {player}." -dra: - - "{player} took on the dragon and didn't survive to tell the story" +# voi <- Void deaths +voi: + - "{player} fell into the void." + - "{player} fell out of the world." + - "{player} went past the space-time continuum." -fro: - - "{player} froze because they couldn't let it go" +# wit <- Wither death messages +wit: + - "{player} was killed by a wither!" + - "A wither annihilated {player}." -oth: - - "{player} died of unknown causes." diff --git a/modules/RoyalCommands/src/main/resources/plugin.yml b/modules/RoyalCommands/src/main/resources/plugin.yml index 808e1a0d..1e6ab7da 100644 --- a/modules/RoyalCommands/src/main/resources/plugin.yml +++ b/modules/RoyalCommands/src/main/resources/plugin.yml @@ -545,7 +545,7 @@ reflectcommands: - murder class: CmdKill description: Kills another player. - usage: '/ [player]' + usage: '/ [player] (cause)' version_added: Pre-0.2.7 killall: aliases: