Update to 1.20 + vault integration + several fixes

This commit is contained in:
yourfriendoss 2024-03-31 20:57:25 +03:00
parent 94973b8296
commit 8eb328b0f7
10 changed files with 99 additions and 201 deletions

42
pom.xml
View file

@ -39,7 +39,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -51,6 +51,12 @@
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.13.0</version>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
@ -93,40 +99,6 @@
</executions>
</plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -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).

View file

@ -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<UUID, Animal> users = new HashMap<UUID, Animal>();
public static HashMap<UUID, Boolean> isChatModOff = new HashMap<UUID, Boolean>();
public static HashMap<UUID, Cooldown> cooldowns = new HashMap<UUID, Cooldown>();
public static HashMap<String, Animal> animals = new HashMap<String, Animal>();
public static HashMap<UUID, Animal> users;
public static HashMap<UUID, Boolean> isChatModOff;
public static HashMap<UUID, Cooldown> cooldowns;
public static HashMap<String, Animal> 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<Chat> 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<UUID, Animal>();
AnimalRP.isChatModOff = new HashMap<UUID, Boolean>();
AnimalRP.cooldowns = new HashMap<UUID, Cooldown>();
AnimalRP.animals = new HashMap<String, Animal>();
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"));

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -39,7 +39,7 @@ public class TfCommand implements CommandExecutor {
Animal previous = AnimalRP.users.get(player.getUniqueId());
player.sendMessage(AnimalRP.mm.deserialize("<green>You start splitting apart, dropping your <blue>" + previous.name+"-like<green> 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 {

View file

@ -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("<red>Elytras are not allowed to be worn. You <green>can still trade with them <red>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());
}
}

View file

@ -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;
Team team;
Component suffix;
Component prefix;
public CustomChatRenderer(Animal animal) {
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());
final Animal animal = AnimalRP.users.get(event.getPlayer().getUniqueId());
Boolean chatModOff = false;
Team team = Bukkit.getServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(event.getPlayer());
if(animal != null) {
if(AnimalRP.isChatModOff.get(event.getPlayer().getUniqueId())) return;
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);
}
event.renderer(new CustomChatRenderer(animal));
});
}
}
}
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);
}
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));
}
}
}

View file

@ -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.