Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 28ba41986d | |||
| cde9bed6dc | |||
| 1ea5d62b57 | |||
| 990b81f079 | |||
| 88c56f5eae |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.youhavetrouble</groupId>
|
<groupId>me.youhavetrouble</groupId>
|
||||||
<artifactId>BeHappyThatItHappened</artifactId>
|
<artifactId>BeHappyThatItHappened</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>BeHappyThatItHappened</name>
|
<name>BeHappyThatItHappened</name>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.papermc.paper</groupId>
|
<groupId>io.papermc.paper</groupId>
|
||||||
<artifactId>paper-api</artifactId>
|
<artifactId>paper-api</artifactId>
|
||||||
<version>1.18.1-R0.1-SNAPSHOT</version>
|
<version>1.19.4-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
### Don't be sad it's gone, be happy that it happened.
|
### Don't be sad it's gone, be happy that it happened.
|
||||||
|
|
||||||
Allows you to collect remains of your named companions.
|
Allows you to collect remains of your named companions.
|
||||||
|
|
||||||
|
#### Configuration
|
||||||
|
|
||||||
|
You can reload the configuration with `/bhihreload` while having `bhih.reload` permission
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
named-entity:
|
||||||
|
rename-drops: true # should mob drops be renamed to the name of the mob
|
||||||
|
drop-nametag: false # should mobs drop (unusable) nametags with their name to be used as mementos
|
||||||
|
player:
|
||||||
|
drop-nametag: false # should players drop (unusable) nametags with their name to be used as mementos
|
||||||
|
```
|
||||||
@@ -1,12 +1,31 @@
|
|||||||
package me.youhavetrouble.behappythatithappened;
|
package me.youhavetrouble.behappythatithappened;
|
||||||
|
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class BeHappyThatItHappened extends JavaPlugin {
|
public class BeHappyThatItHappened extends JavaPlugin {
|
||||||
|
|
||||||
|
protected boolean renameDrops = true;
|
||||||
|
protected boolean renamedMobsDropTag = false;
|
||||||
|
protected boolean playersDropTag = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getServer().getPluginManager().registerEvents(new SadMomentListener(), this);
|
reloadSadness();
|
||||||
|
getServer().getPluginManager().registerEvents(new SadMomentListener(this), this);
|
||||||
|
PluginCommand command = getCommand("bhihreload");
|
||||||
|
if (command == null) {
|
||||||
|
getLogger().warning("You messed with the plugin.yml, didn't you?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
command.setExecutor(new ReloadCommand(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void reloadSadness() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
renameDrops = getConfig().getBoolean("named-entity.rename-drops", true);
|
||||||
|
renamedMobsDropTag = getConfig().getBoolean("named-entity.drop-nametag", false);
|
||||||
|
playersDropTag = getConfig().getBoolean("player.drop-nametag", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package me.youhavetrouble.behappythatithappened;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ReloadCommand implements TabExecutor {
|
||||||
|
|
||||||
|
private final BeHappyThatItHappened plugin;
|
||||||
|
|
||||||
|
public ReloadCommand(BeHappyThatItHappened plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||||
|
plugin.reloadSadness();
|
||||||
|
commandSender.sendMessage("Reloaded BeHappyThatItHappened config.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,135 @@
|
|||||||
package me.youhavetrouble.behappythatithappened;
|
package me.youhavetrouble.behappythatithappened;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.entity.TameableDeathMessageEvent;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Mob;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Tameable;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class SadMomentListener implements Listener {
|
public class SadMomentListener implements Listener {
|
||||||
|
|
||||||
|
private final ItemMeta nametagMeta = new ItemStack(Material.NAME_TAG).getItemMeta();
|
||||||
|
private final NamespacedKey inMemoryOfKey;
|
||||||
|
private final BeHappyThatItHappened plugin;
|
||||||
|
|
||||||
|
protected SadMomentListener(BeHappyThatItHappened plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
inMemoryOfKey = new NamespacedKey(plugin, "in-memory-of");
|
||||||
|
nametagMeta.getPersistentDataContainer().set(inMemoryOfKey, PersistentDataType.STRING, "");
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onSadMoment(EntityDeathEvent event) {
|
public void onSadMoment(EntityDeathEvent event) {
|
||||||
|
|
||||||
if (event.getEntityType().equals(EntityType.PLAYER)) return;
|
if (event.getEntityType().equals(EntityType.PLAYER)) return;
|
||||||
String inMemoryOf = event.getEntity().getCustomName();
|
if (!(event.getEntity() instanceof Mob)) return;
|
||||||
|
if (event.getEntity() instanceof Tameable) {
|
||||||
|
Tameable pet = (Tameable) event.getEntity();
|
||||||
|
if (pet.isTamed()) return;
|
||||||
|
}
|
||||||
|
Component inMemoryOf = event.getEntity().customName();
|
||||||
if (inMemoryOf == null) return;
|
if (inMemoryOf == null) return;
|
||||||
|
|
||||||
event.getDrops().forEach(memento -> {
|
if (plugin.renameDrops) {
|
||||||
ItemMeta respect = memento.getItemMeta();
|
event.getDrops().forEach(memento -> {
|
||||||
if (respect.hasDisplayName()) return;
|
ItemMeta respect = memento.getItemMeta();
|
||||||
respect.setDisplayName(inMemoryOf);
|
if (respect.hasDisplayName()) return;
|
||||||
memento.setItemMeta(respect);
|
respect.displayName(inMemoryOf);
|
||||||
});
|
memento.setItemMeta(respect);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.renamedMobsDropTag) {
|
||||||
|
event.getDrops().add(getMemento(inMemoryOf, null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onSevereLossMoment(TameableDeathMessageEvent event) {
|
||||||
|
if (!plugin.renamedMobsDropTag) return;
|
||||||
|
if (!event.getEntity().isTamed()) return;
|
||||||
|
ItemStack memento = getMemento(event.getEntity().customName(), event.deathMessage());
|
||||||
|
event.getEntity().getWorld().dropItemNaturally(event.getEntity().getLocation(), memento);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onLossMoment(PlayerDeathEvent event) {
|
||||||
|
if (!plugin.playersDropTag) return;
|
||||||
|
Player player = event.getEntity();
|
||||||
|
ItemStack memento = getMemento(player.displayName(), event.deathMessage());
|
||||||
|
event.getDrops().add(memento);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onDesecration(PrepareAnvilEvent event) {
|
||||||
|
ItemStack left = event.getInventory().getFirstItem();
|
||||||
|
if (left == null) return;
|
||||||
|
if (!Material.NAME_TAG.equals(left.getType())) return;
|
||||||
|
ItemMeta meta = left.getItemMeta();
|
||||||
|
PersistentDataContainer pdc = meta.getPersistentDataContainer();
|
||||||
|
if (!pdc.has(inMemoryOfKey, PersistentDataType.STRING)) return;
|
||||||
|
event.setResult(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onDesecration(PlayerInteractEntityEvent event) {
|
||||||
|
ItemStack held = event.getPlayer().getInventory().getItemInMainHand();
|
||||||
|
if (!Material.NAME_TAG.equals(held.getType())) return;
|
||||||
|
ItemMeta meta = held.getItemMeta();
|
||||||
|
PersistentDataContainer pdc = meta.getPersistentDataContainer();
|
||||||
|
if (!pdc.has(inMemoryOfKey, PersistentDataType.STRING)) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onDesecration(EntityDamageEvent event) {
|
||||||
|
if (!(event.getEntityType().equals(EntityType.DROPPED_ITEM))) return;
|
||||||
|
if (event.getCause().equals(EntityDamageEvent.DamageCause.VOID)) return;
|
||||||
|
ItemStack item = ((org.bukkit.entity.Item) event.getEntity()).getItemStack();
|
||||||
|
if (!Material.NAME_TAG.equals(item.getType())) return;
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
PersistentDataContainer pdc = meta.getPersistentDataContainer();
|
||||||
|
if (!pdc.has(inMemoryOfKey, PersistentDataType.STRING)) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack getMemento(Component name, Component message) {
|
||||||
|
ItemStack nametag = new ItemStack(Material.NAME_TAG);
|
||||||
|
ItemMeta meta = nametagMeta;
|
||||||
|
meta.displayName(Component.text("In memory of ").append(name)
|
||||||
|
.decoration(TextDecoration.ITALIC, false)
|
||||||
|
.color(NamedTextColor.WHITE));
|
||||||
|
if (message != null) {
|
||||||
|
List<Component> lore = new ArrayList<>();
|
||||||
|
lore.add(message
|
||||||
|
.decoration(TextDecoration.ITALIC, false)
|
||||||
|
.color(NamedTextColor.GRAY)
|
||||||
|
);
|
||||||
|
meta.lore(lore);
|
||||||
|
} else {
|
||||||
|
meta.lore(null);
|
||||||
|
}
|
||||||
|
nametag .setItemMeta(meta);
|
||||||
|
return nametag;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
named-entity:
|
||||||
|
rename-drops: true
|
||||||
|
drop-nametag: false
|
||||||
|
player:
|
||||||
|
drop-nametag: false
|
||||||
@@ -1,7 +1,17 @@
|
|||||||
name: BeHappyThatItHappened
|
name: BeHappyThatItHappened
|
||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: me.youhavetrouble.behappythatithappened.BeHappyThatItHappened
|
main: me.youhavetrouble.behappythatithappened.BeHappyThatItHappened
|
||||||
api-version: 1.18
|
api-version: 1.19
|
||||||
authors: [ YouHaveTrouble ]
|
authors: [ YouHaveTrouble ]
|
||||||
description: Don't be sad that they're gone, be happy they happened
|
description: Don't be sad that they're gone, be happy they happened
|
||||||
website: youhavetrouble.me
|
website: youhavetrouble.me
|
||||||
|
commands:
|
||||||
|
bhihreload:
|
||||||
|
description: Reloads the plugin
|
||||||
|
usage: /bhihreload
|
||||||
|
permission: bhih.reload
|
||||||
|
permission-message: You do not have permission to use this command
|
||||||
|
permissions:
|
||||||
|
bhih.reload:
|
||||||
|
description: Allows the user to reload the plugin
|
||||||
|
default: op
|
||||||
|
|||||||
Reference in New Issue
Block a user