From 8eb328b0f7f39216df2f88fd320f50770482e239 Mon Sep 17 00:00:00 2001
From: yourfriendoss <81387799+yourfriendoss@users.noreply.github.com>
Date: Sun, 31 Mar 2024 20:57:25 +0300
Subject: [PATCH] Update to 1.20 + vault integration + several fixes
---
pom.xml | 42 ++-------
readme.md | 4 +-
src/main/java/lv/pi/animalrp/AnimalRP.java | 31 +++++--
.../java/lv/pi/animalrp/animals/Phantom.java | 43 ---------
.../pi/animalrp/commands/ChatModCommand.java | 2 +-
.../commands/ClearCooldownCommand.java | 2 +-
.../lv/pi/animalrp/commands/TfCommand.java | 2 +-
.../lv/pi/animalrp/listeners/AntiElytra.java | 93 -------------------
.../lv/pi/animalrp/listeners/PlayerChat.java | 77 ++++++++++++---
src/main/resources/plugin.yml | 4 +-
10 files changed, 99 insertions(+), 201 deletions(-)
delete mode 100644 src/main/java/lv/pi/animalrp/animals/Phantom.java
delete mode 100644 src/main/java/lv/pi/animalrp/listeners/AntiElytra.java
diff --git a/pom.xml b/pom.xml
index 6770ada..6f84127 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@
io.papermc.paper
paper-api
- 1.19.4-R0.1-SNAPSHOT
+ 1.20.4-R0.1-SNAPSHOT
provided
@@ -51,6 +51,12 @@
net.kyori
adventure-text-serializer-legacy
4.13.0
+
+
+ com.github.MilkBowl
+ VaultAPI
+ 1.7
+ provided
@@ -93,40 +99,6 @@
-
-
- net.md-5
- specialsource-maven-plugin
- 1.2.2
-
-
- package
-
- remap
-
- remap-obf
-
- org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:txt:maps-mojang
- true
- org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-mojang
- true
- remapped-obf
-
-
-
- package
-
- remap
-
- remap-spigot
-
- ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
- org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:csrg:maps-spigot
- org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-obf
-
-
-
-
diff --git a/readme.md b/readme.md
index 034d526..fa10bf8 100644
--- a/readme.md
+++ b/readme.md
@@ -7,11 +7,9 @@ Doubleclicking shift you will float (levitation 5 for 1 second), allowing for be
You take significantly less damage when falling (5 hearts). You can still die, don't count on your cat-powers catching you every time. **Your superfood is all types of eatable fish.**
3. Fox
You do more damage to mobs (25%). **Your superfood is all types of berry.**
-4. Phantom
-You can use elytras, however you burn in daylight and your elytra speed is capped at half of the normal one. **Your superfoods are all uncooked meats.**
## **Chat**
-Chat while you are a animal is very different. When you speak, your words will become furry-ified and every time you talk you'll have animal sounds come out of you.
+Chat while you are a animal is very different. When you speak, your words will become furry-ified and every time you talk you'll have animal sounds come out of you. You can disable this via /chatmodoff, and turn it back on via /chatmodon.
## **Superfoods**
Superfoods are items that when eaten, give you stackable **Speed II** and insane amounts of saturation (9.4 points) and hunger (4 points).
diff --git a/src/main/java/lv/pi/animalrp/AnimalRP.java b/src/main/java/lv/pi/animalrp/AnimalRP.java
index 3387bf2..6a14516 100644
--- a/src/main/java/lv/pi/animalrp/AnimalRP.java
+++ b/src/main/java/lv/pi/animalrp/AnimalRP.java
@@ -37,6 +37,7 @@ import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson;
@@ -55,20 +56,23 @@ import lv.pi.animalrp.commands.ChatModCommand;
import lv.pi.animalrp.commands.ClearCooldownCommand;
import lv.pi.animalrp.commands.SexCommand;
import lv.pi.animalrp.commands.TfCommand;
-import lv.pi.animalrp.listeners.AntiElytra;
import lv.pi.animalrp.listeners.PlayerChat;
import lv.pi.animalrp.util.Cooldown;
import lv.pi.animalrp.util.Emote;
import lv.pi.animalrp.util.Mood;
import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.milkbowl.vault.chat.Chat;
+import net.milkbowl.vault.economy.Economy;
public class AnimalRP extends JavaPlugin {
- public static HashMap users = new HashMap();
- public static HashMap isChatModOff = new HashMap();
- public static HashMap cooldowns = new HashMap();
- public static HashMap animals = new HashMap();
+ public static HashMap users;
+ public static HashMap isChatModOff;
+ public static HashMap cooldowns;
+ public static HashMap animals;
public static Emote emotes;
+ public static Chat vaultChat;
+
public static Boolean configEnabled = true;
private Gson gson;
public static MiniMessage mm = MiniMessage.miniMessage();
@@ -120,15 +124,25 @@ public class AnimalRP extends JavaPlugin {
@Override
public void onEnable() {
- PluginManager pm = getServer().getPluginManager();
+ RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Chat.class);
+ if(rsp != null) {
+ AnimalRP.vaultChat = rsp.getProvider();
+ } else {
+ System.out.println("[AnimalRP] !!! Missing vault, prefix/suffix will not be included in chat formatting.");
+ }
+ AnimalRP.users = new HashMap();
+ AnimalRP.isChatModOff = new HashMap();
+ AnimalRP.cooldowns = new HashMap();
+ AnimalRP.animals = new HashMap();
+
AnimalRP.emotes = new Emote();
+ PluginManager pm = getServer().getPluginManager();
this.gson = new Gson();
animals.put("cat", new Cat());
animals.put("fox", new Fox());
animals.put("bee", new Bee());
- // animals.put("phantom", new Phantom()); // finish Phantom
animals.forEach((z,b) -> {
pm.registerEvents(b, this);
@@ -181,7 +195,6 @@ public class AnimalRP extends JavaPlugin {
}
pm.registerEvents(new PlayerChat(), this);
- pm.registerEvents(new AntiElytra(), this);
getCommand("tf").setExecutor(new TfCommand());
getCommand("emote").setExecutor(new EmoteCommand());
@@ -197,9 +210,9 @@ public class AnimalRP extends JavaPlugin {
getCommand("headpats").setExecutor(new InteractionCommand(Mood.HAPPY, "%s petted you! %s", "You petted %s! %s"));
getCommand("kiss").setExecutor(new InteractionCommand(Mood.CUTE, "%s kissed you.. 0////0 %s", "You kissed %s.. 0////0 %s"));
getCommand("bite").setExecutor(new InteractionCommand(Mood.ANGRY, "%s bit you!! Σ(っ゚Д゚)っ %s", "You bit %s! (○`д´)ノシ %s"));
+ getCommand("bzz").setExecutor(new InteractionCommand(Mood.ANGRY, "%s bzzs at you!! :3 %s", "You bzzed at %s :3 %s"));
getCommand("purr").setExecutor(new InteractionCommand(Mood.CUTE, "You hear the soft sound of %s purring on you... %s", "You jump on %s, and start purring. %s"));
getCommand("scratch").setExecutor(new InteractionCommand(Mood.ANGRY, "%s SCRATCHES YOU! Ow! %s", "You channel your inner evil, and scratch %s! %s"));
-
/* Contributed by Simo__28 */
getCommand("hug").setExecutor(new InteractionCommand(Mood.HAPPY, "%s hugs you! How heartwarming. %s", "You hug %s! How heartwarming. %s"));
getCommand("cuddle").setExecutor(new InteractionCommand(Mood.CUTE, "%s cuddles with you. %s", "You and %s start cuddling. How cute! %s"));
diff --git a/src/main/java/lv/pi/animalrp/animals/Phantom.java b/src/main/java/lv/pi/animalrp/animals/Phantom.java
deleted file mode 100644
index 8b84e8a..0000000
--- a/src/main/java/lv/pi/animalrp/animals/Phantom.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package lv.pi.animalrp.animals;
-
-import java.util.Random;
-
-import org.bukkit.Material;
-import org.bukkit.Sound;
-
-import lv.pi.animalrp.util.Mood;
-import lv.pi.animalrp.util.TextDestroyer;
-
-public class Phantom extends Animal {
- TextDestroyer destroyer = new TextDestroyer(new String[]{
- "*shows wings*",
- "*flap flap*",
- "*screech*",
- ":3"
- }, new String[][]{
- {"you", "u"},
- {"o", "sho"},
- {"i", "ish"},
- {"!", "! "},
- {"?", "? "}
- });
- Random rand = new Random();
-
- public Phantom() {
- super("phantom", "~screech~", "#FF8000");
- this.moodSounds.put(Mood.HAPPY, Sound.ENTITY_PHANTOM_FLAP);
- this.moodSounds.put(Mood.CUTE, Sound.ENTITY_PHANTOM_SWOOP);
- this.moodSounds.put(Mood.SAD, Sound.ENTITY_PHANTOM_SWOOP);
- this.moodSounds.put(Mood.STRESSED, Sound.ENTITY_PHANTOM_HURT);
- this.moodSounds.put(Mood.ANGRY, Sound.ENTITY_PHANTOM_BITE);
-
- this.superfoods.add(Material.CHICKEN);
- this.superfoods.add(Material.BEEF);
- this.superfoods.add(Material.PORKCHOP);
- }
-
- @Override
- public String chatTransformations(String message) {
- return this.destroyer.destroy(message);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java b/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java
index 2f0aabe..e3ff81f 100644
--- a/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java
+++ b/src/main/java/lv/pi/animalrp/commands/ChatModCommand.java
@@ -25,7 +25,7 @@ public class ChatModCommand implements CommandExecutor {
boolean isDisabled = false;
- if(AnimalRP.isChatModOff.get(player.getUniqueId())) {
+ if(AnimalRP.isChatModOff.get(player.getUniqueId()) != null) {
isDisabled = true;
}
diff --git a/src/main/java/lv/pi/animalrp/commands/ClearCooldownCommand.java b/src/main/java/lv/pi/animalrp/commands/ClearCooldownCommand.java
index 9378d44..40e44b7 100644
--- a/src/main/java/lv/pi/animalrp/commands/ClearCooldownCommand.java
+++ b/src/main/java/lv/pi/animalrp/commands/ClearCooldownCommand.java
@@ -46,7 +46,7 @@ public class ClearCooldownCommand implements CommandExecutor {
}
AnimalRP.cooldowns.remove(of.getUniqueId());
- sender.sendMessage(AnimalRP.mm.deserialize("Removed" + of.getName() + "'s cooldown (type: " + cooldown.type + ")!"));
+ sender.sendMessage(AnimalRP.mm.deserialize("Removed " + of.getName() + "'s cooldown (type: " + cooldown.type + ")!"));
return true;
}
}
diff --git a/src/main/java/lv/pi/animalrp/commands/TfCommand.java b/src/main/java/lv/pi/animalrp/commands/TfCommand.java
index c090953..38d7eac 100644
--- a/src/main/java/lv/pi/animalrp/commands/TfCommand.java
+++ b/src/main/java/lv/pi/animalrp/commands/TfCommand.java
@@ -39,7 +39,7 @@ public class TfCommand implements CommandExecutor {
Animal previous = AnimalRP.users.get(player.getUniqueId());
player.sendMessage(AnimalRP.mm.deserialize("You start splitting apart, dropping your " + previous.name+"-like appearence.."));
AnimalRP.users.remove(player.getUniqueId());
- if(AnimalRP.isChatModOff.get(player.getUniqueId()))
+ if(AnimalRP.isChatModOff.get(player.getUniqueId()) != null)
AnimalRP.isChatModOff.remove(player.getUniqueId());
return true;
} else {
diff --git a/src/main/java/lv/pi/animalrp/listeners/AntiElytra.java b/src/main/java/lv/pi/animalrp/listeners/AntiElytra.java
deleted file mode 100644
index 3720b5d..0000000
--- a/src/main/java/lv/pi/animalrp/listeners/AntiElytra.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package lv.pi.animalrp.listeners;
-
-import org.bukkit.GameMode;
-import org.bukkit.Location;
-import org.bukkit.Material;
-import org.bukkit.entity.EntityType;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.Action;
-import org.bukkit.event.entity.EntityToggleGlideEvent;
-import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.PlayerInventory;
-import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.scheduler.BukkitRunnable;
-
-import lv.pi.animalrp.AnimalRP;
-import lv.pi.animalrp.animals.Animal;
-
-public class AntiElytra implements Listener {
-
- public AntiElytra() {
- JavaPlugin plugin = AnimalRP.getProvidingPlugin(AnimalRP.class);
-
- new BukkitRunnable(){
- public void run(){
- for(Player p : plugin.getServer().getOnlinePlayers())
- dequipElytra(p);
- }
- }.runTaskTimer(plugin, 20 * 5, 20 * 5);
- }
-
- private void message(Player player) {
- player.sendMessage(AnimalRP.mm.deserialize("Elytras are not allowed to be worn. You can still trade with them as they might have a use in the future."));
- }
- @EventHandler
- public void onGlide(EntityToggleGlideEvent event) {
- if (event.getEntity().getType().equals(EntityType.PLAYER))
- dequipElytra((Player) event.getEntity());
- }
-
- private int firstEmptyFromBack(PlayerInventory inv) {
- int z = -1;
-
- for(int i = 35; i >= 9; i--) {
- if(inv.getItem(i) == null) {
- z = i;
- break;
- }
- }
-
- return z;
- }
-
- private void dequipElytra(Player player) {
- Animal animal = AnimalRP.users.get(player.getUniqueId());
-
- if(animal != null) {
- if(animal.name == "phantom") return; // phantom-ians can use elytra
- }
-
- PlayerInventory i = player.getInventory();
- if (!( (i.getChestplate() != null) && i.getChestplate().getType().equals(Material.ELYTRA))) return;
- if(player.getGameMode() == GameMode.CREATIVE) return;
-
- ItemStack elytra = i.getChestplate();
- i.setChestplate(null);
- message(player);
-
- // inventory full?
- if (firstEmptyFromBack(i) != -1) {
- i.setItem(firstEmptyFromBack(i), elytra);
- player.updateInventory();
- } else {
- Location l = i.getLocation();
- l.getWorld().dropItemNaturally(l, elytra);
- player.updateInventory();
- }
- }
-
- @EventHandler
- public void onInteract(PlayerInteractEvent event) {
- Action a = event.getAction();
- if(a == Action.PHYSICAL || a == Action.LEFT_CLICK_AIR || a == Action.LEFT_CLICK_BLOCK) return;
-
- if(event.getItem() == null) return;
- if(event.getItem().getType() != Material.ELYTRA) return;
- if(event.getPlayer().getGameMode() == GameMode.CREATIVE) return;
- message(event.getPlayer());
- dequipElytra(event.getPlayer());
- }
-}
\ No newline at end of file
diff --git a/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java b/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java
index 0ffae2a..c8ecbae 100644
--- a/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java
+++ b/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java
@@ -2,10 +2,12 @@ package lv.pi.animalrp.listeners;
import java.util.Random;
+import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
+import org.bukkit.scoreboard.Team;
import org.jetbrains.annotations.NotNull;
import io.papermc.paper.chat.ChatRenderer;
@@ -20,20 +22,42 @@ import lv.pi.animalrp.AnimalRP;
class CustomChatRenderer implements ChatRenderer {
Animal animal;
-
- public CustomChatRenderer(Animal animal) {
+ Team team;
+ Component suffix;
+ Component prefix;
+
+ public CustomChatRenderer(Animal animal, Team team, Component suffix, Component prefix) {
this.animal = animal;
+ this.team = team;
+ this.suffix = suffix;
+ this.prefix = prefix;
}
@Override
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message,
@NotNull Audience viewer) {
- return Component
- .text("<")
- .append(sourceDisplayName.color(TextColor.fromHexString(animal.color)))
- .append(Component.text(">"))
+ Component name = sourceDisplayName;
+
+ if(team != null) {
+ name = name.color(team.color());
+ }
+
+ if(animal != null) {
+ name = name.color(TextColor.fromHexString(animal.color));
+ }
+
+ Component msg = message;
+
+ if(animal != null) {
+ msg = AnimalRP.mm.deserialize(animal.chatTransformations(AnimalRP.mm.serialize(message)));
+ }
+
+ return this.prefix
+ .append(name)
+ .append(this.suffix)
+ .append(Component.text(":"))
.appendSpace()
- .append(AnimalRP.mm.deserialize(animal.chatTransformations(AnimalRP.mm.serialize(message))));
+ .append(msg);
}
};
@@ -42,16 +66,41 @@ public class PlayerChat implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(final AsyncChatEvent event) {
- Animal animal = AnimalRP.users.get(event.getPlayer().getUniqueId());
-
- if(animal != null) {
- if(AnimalRP.isChatModOff.get(event.getPlayer().getUniqueId())) return;
+ final Animal animal = AnimalRP.users.get(event.getPlayer().getUniqueId());
+ Boolean chatModOff = false;
+ Team team = Bukkit.getServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(event.getPlayer());
- if(random.nextDouble() < 0.08) {
- event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), animal.moodSounds.get(Mood.HAPPY), 10F, 1);
+ if(animal != null) {
+ if(AnimalRP.isChatModOff.get(event.getPlayer().getUniqueId()) != null) {
+ chatModOff = true;
+ } else {
+ if(random.nextDouble() < 0.08) {
+ Bukkit.getScheduler().runTask(AnimalRP.getPlugin(AnimalRP.class), () -> {
+ event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), animal.moodSounds.get(Mood.HAPPY), 10F, 1);
+ });
+ }
+ }
+ }
+
+ Component csuffix = Component.text("");
+ Component cprefix = Component.text("");
+
+ if(AnimalRP.vaultChat != null) {
+ String suffix = AnimalRP.vaultChat.getPlayerSuffix(event.getPlayer());
+ String prefix = AnimalRP.vaultChat.getPlayerPrefix(event.getPlayer());
+
+ if(suffix != null) {
+ csuffix = Component.text(suffix);
}
- event.renderer(new CustomChatRenderer(animal));
+ if(prefix != null) {
+ cprefix = Component.text(prefix);
+ }
+ }
+ if(chatModOff) {
+ event.renderer(new CustomChatRenderer(null, team, csuffix, cprefix));
+ } else {
+ event.renderer(new CustomChatRenderer(animal, team, csuffix, cprefix));
}
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 24346d6..15fef86 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,7 +1,7 @@
name: animalrp
main: lv.pi.animalrp.AnimalRP
version: 1.0.0
-api-version: 1.19
+api-version: 1.20
commands:
tf:
usage: Become the animal of your dreams!
@@ -30,5 +30,7 @@ commands:
usage: Cuddle a person.
emote:
usage: Emote!
+ bzz:
+ usage: Bzz at someone :3
sex:
usage: This command can only be used by Operators.
\ No newline at end of file