first commit

This commit is contained in:
Soph :3 2024-10-13 15:19:27 +03:00
commit 2f5a4bc647
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
74 changed files with 2126 additions and 0 deletions

View file

@ -0,0 +1,18 @@
apply plugin: 'java'
repositories {
maven {
name = "papermc"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
implementation project(':animalrp-common')
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}

View file

@ -0,0 +1,34 @@
package ovh.sad.animalrp.paper;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.plugin.java.JavaPlugin;
import ovh.sad.animalrp.common.AnimalRP;
import ovh.sad.animalrp.common.util.HashmapStore;
public class AnimalRPPaper extends JavaPlugin implements AnimalRP {
public static HashmapStore hashmapStore;
@Override
public void onEnable() {
AnimalRPPaper.hashmapStore = new HashmapStore(this.getDataFolder().toPath());
this.getLogger().log(Level.INFO, welcomeMessage);
hashmapStore.get("users.json").forEach((k, v) -> {
users.put(UUID.fromString(k), animals.get(v));
});
hashmapStore.get("nochat.json").forEach((k, v) -> {
noChat.put(UUID.fromString(k), Boolean.valueOf(v));
});
}
@Override
public void onDisable() {
hashmapStore.save("users.json", users);
hashmapStore.save("nochat.json", noChat);
}
}

View file

@ -0,0 +1,201 @@
package ovh.sad.animalrp.paper.animals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.FoodComponent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import ovh.sad.animalrp.common.AnimalRP;
import ovh.sad.animalrp.common.util.Animal;
import ovh.sad.animalrp.common.util.Mood;
import ovh.sad.animalrp.common.util.TextDestroyer;
import ovh.sad.animalrp.paper.AnimalRPPaper;
public class Bee extends Animal<Sound, Material> implements Listener {
class Row {
Material mat;
Integer times;
}
private static Material[] _allFlowers = { Material.ALLIUM, Material.AZURE_BLUET, Material.BLUE_ORCHID,
Material.CORNFLOWER, Material.DANDELION, Material.LILY_OF_THE_VALLEY, Material.OXEYE_DAISY,
Material.POPPY, Material.TORCHFLOWER, Material.ORANGE_TULIP, Material.PINK_TULIP, Material.RED_TULIP,
Material.WHITE_TULIP };
public static List<Material> allFlowers = Arrays.asList(_allFlowers);
public static HashMap<UUID, Row> inARow = new HashMap<UUID, Row>();
TextDestroyer destroyer = new TextDestroyer(new String[] {
">_<", "*buzz*",
";3", ":3", "εწз", " ≧◠◡◠≦ ", "*stings you*", "*humms*",
"*i'm a bee*"
}, new String[][] {
{ "e", "ee" },
{ "b", "bzz" },
{ "h", "hh" },
{ "ie", "ee" },
{ "be", "bee" },
{ "E", "EE" },
{ "B", "BZZ" },
{ "H", "HH" },
{ "IE", "EE" },
{ "BE", "BEE" }
});
ArrayList<UUID> sneakers = new ArrayList<UUID>();
public static Boolean isItemARP(ItemStack is) {
return (allFlowers.contains(is.getType()) && is.getItemMeta().hasFood());
}
public Bee() {
super("bee", "Buzz...", "#FFFF00");
this.moodSounds.put(Mood.HAPPY, Sound.ENTITY_BEE_LOOP);
this.moodSounds.put(Mood.CUTE, Sound.ENTITY_BEE_LOOP);
this.moodSounds.put(Mood.SAD, Sound.ENTITY_BEE_HURT);
this.moodSounds.put(Mood.STRESSED, Sound.ENTITY_BEE_STING);
this.moodSounds.put(Mood.ANGRY, Sound.ENTITY_BEE_LOOP_AGGRESSIVE);
}
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Animal<?,?> animal = AnimalRP.users.get(player.getUniqueId());
ItemStack item = event.getItem();
if (item == null) // air interact
return;
if (!allFlowers.contains(item.getType())) { // not a flower
return;
}
ItemMeta meta = item.getItemMeta();
Boolean incorrect = false;
if (animal == null) {
incorrect = true;
} else {
if (animal.name != this.name) {
incorrect = true;
}
}
if (incorrect) {
if (Bee.isItemARP(item)) {
meta.setFood(null);
item.setItemMeta(meta);
event.setCancelled(true);
}
return;
}
if (Bee.isItemARP(item)) { // correct animal, but foodkey already set
return;
}
FoodComponent food = meta.getFood();
food.addEffect(new PotionEffect(PotionEffectType.SPEED, 20 * 4, 1, true), 1);
food.setCanAlwaysEat(true);
food.setNutrition(4); // these values match the 'superfood' of animalrps
food.setSaturation(9.4f);
meta.setFood(food);
item.setItemMeta(meta);
}
@EventHandler
public void onConsume(PlayerItemConsumeEvent event) {
Player player = event.getPlayer();
Animal<?,?> animal = AnimalRP.users.get(player.getUniqueId());
ItemStack item = event.getItem();
if (!allFlowers.contains(item.getType())) { // not a flower
return;
}
if (animal == null)
return;
if (animal.name != this.name)
return;
Row row = inARow.get(player.getUniqueId()); // make a new row
if (row == null) { // none yet
row = new Row();
row.mat = item.getType();
row.times = 1;
} else {
if (row.mat.equals(item.getType())) { // mat is same as in row, increase time
row.times += 1;
} else {
row.mat = item.getType(); // mat not same, change mat, reset time
row.times = 1;
}
}
if (row.times > 20) {
player.addPotionEffect(new PotionEffect(PotionEffectType.NAUSEA, 20 * 10, 1, true));
}
if (row.times > 30) {
if (row.times > 40) {
player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20 * 10, 3, true));
} else {
player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20 * 5, 2, true));
}
}
inARow.put(player.getUniqueId(), row);
}
@EventHandler
public void onSneak(PlayerToggleSneakEvent event) {
Animal<?,?> animal = AnimalRP.users.get(event.getPlayer().getUniqueId());
if (animal == null)
return;
if (animal.name != this.name)
return;
Material type = event.getPlayer().getLocation().getBlock().getRelative(BlockFace.DOWN).getType();
if (event.isSneaking()
&& type != Material.AIR && type != Material.WATER) {
Player player = event.getPlayer();
if (!sneakers.contains(player.getUniqueId())) {
sneakers.add(player.getUniqueId());
new BukkitRunnable() {
@Override
public void run() {
if (sneakers.contains(player.getUniqueId()))
sneakers.remove(player.getUniqueId());
}
}.runTaskLater(AnimalRPPaper.getProvidingPlugin(Animal.class), 20);
} else {
sneakers.remove(player.getUniqueId());
player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 20 * 1, 5, true));
player.getWorld().playSound(player.getLocation(), this.moodSounds.get(Mood.HAPPY), 1F, 1);
}
}
}
@Override
public String chatTransformations(String message) {
return destroyer.destroy(message);
}
}

View file

@ -0,0 +1,62 @@
package ovh.sad.animalrp.paper.animals;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import ovh.sad.animalrp.common.AnimalRP;
import ovh.sad.animalrp.common.util.Animal;
import ovh.sad.animalrp.common.util.Mood;
import ovh.sad.animalrp.common.util.TextDestroyer;
public class Cat extends Animal<Sound, Material> {
TextDestroyer destroyer = new TextDestroyer(new String[]{
">_<", ":3", "ʕʘ‿ʘʔ", ":D", "._.",
";3", "xD", "ㅇㅅㅇ",
">_>", "ÙωÙ", "UwU", "OwO", ":P",
"(◠‿◠✿)", "^_^", ";_;",
"x3", "(• o •)", "<_<"
}, new String[][]{
{"l", "w"},
{"r", "w"},
{"th", "d"},
{"L", "W"},
{"R", "W"},
{"TH", "D"}
});
public Cat() {
super("cat", "Nya~", "#F2BDCD");
this.moodSounds.put(Mood.HAPPY, Sound.ENTITY_CAT_PURR);
this.moodSounds.put(Mood.CUTE, Sound.ENTITY_CAT_PURREOW);
this.moodSounds.put(Mood.SAD, Sound.ENTITY_CAT_AMBIENT);
this.moodSounds.put(Mood.STRESSED, Sound.ENTITY_CAT_STRAY_AMBIENT);
this.moodSounds.put(Mood.ANGRY, Sound.ENTITY_CAT_HISS);
this.superfoods.add(Material.COOKED_COD);
this.superfoods.add(Material.COD);
this.superfoods.add(Material.COOKED_SALMON);
this.superfoods.add(Material.SALMON);
}
@EventHandler
public void onDamage(EntityDamageEvent event) {
if(!(event.getEntity() instanceof Player)) return;
Player player = (Player)event.getEntity();
Animal<?,?> animal = AnimalRP.users.get(player.getUniqueId());
if(animal == null) return;
if(animal.name != this.name) return;
if(event.getCause() == DamageCause.FALL) {
event.setDamage(event.getDamage() - 5);
}
}
@Override
public String chatTransformations(String message) {
return destroyer.destroy(message);
}
}

View file

@ -0,0 +1,54 @@
package ovh.sad.animalrp.paper.animals;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import ovh.sad.animalrp.common.util.Animal;
import ovh.sad.animalrp.common.util.Mood;
import ovh.sad.animalrp.common.util.TextDestroyer;
import ovh.sad.animalrp.paper.AnimalRPPaper;
public class Dog extends Animal<Sound, Material> {
TextDestroyer destroyer = new TextDestroyer(new String[]{
"Woof!", "Bark :3",
"Arf", "bark bark bark", "arf~"
}, new String[][]{
});
public Dog() {
super("dog", "Arf!", "#ff8c00");
this.moodSounds.put(Mood.HAPPY, Sound.ENTITY_WOLF_AMBIENT);
this.moodSounds.put(Mood.CUTE, Sound.ENTITY_WOLF_STEP);
this.moodSounds.put(Mood.SAD, Sound.ENTITY_WOLF_WHINE);
this.moodSounds.put(Mood.STRESSED, Sound.ENTITY_WOLF_SHAKE);
this.moodSounds.put(Mood.ANGRY, Sound.ENTITY_WOLF_GROWL);
this.superfoods.add(Material.CHICKEN);
this.superfoods.add(Material.BEEF);
this.superfoods.add(Material.PORKCHOP);
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if(event.getEntity() instanceof Player) {
Player player = (Player)event.getEntity();
Animal<?, ?> animal = AnimalRPPaper.users.get(player.getUniqueId());
if(animal == null) return;
if(animal.name != this.name) return;
player.removePotionEffect(PotionEffectType.SPEED);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 20, 2));
}
}
@Override
public String chatTransformations(String message) {
return destroyer.destroy(message);
}
}

View file

@ -0,0 +1,67 @@
package ovh.sad.animalrp.paper.animals;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import ovh.sad.animalrp.common.AnimalRP;
import ovh.sad.animalrp.common.util.Animal;
import ovh.sad.animalrp.common.util.Mood;
import ovh.sad.animalrp.common.util.TextDestroyer;
public class Fox extends Animal<Sound, Material> implements Listener {
TextDestroyer destroyer = new TextDestroyer(new String[]{
"yap",
"*yap yap*",
"*beeps*",
"*barks*",
"*screeches*",
":3"
}, new String[][]{
{"you", "u"},
{"o", "yo"},
{"i", "yi"},
{"!", " !"},
{"?", " ?"}
});
Random rand = new Random();
public Fox() {
super("fox", "Yap!", "#FF8000");
this.moodSounds.put(Mood.HAPPY, Sound.ENTITY_FOX_SNIFF);
this.moodSounds.put(Mood.CUTE, Sound.ENTITY_FOX_SLEEP);
this.moodSounds.put(Mood.SAD, Sound.ENTITY_FOX_SNIFF);
this.moodSounds.put(Mood.STRESSED, Sound.ENTITY_FOX_AGGRO);
this.moodSounds.put(Mood.ANGRY, Sound.ENTITY_FOX_BITE);
this.superfoods.add(Material.APPLE);
this.superfoods.add(Material.GLOW_BERRIES);
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event) {
if(event.getDamager() instanceof Player) {
Player player = (Player)event.getDamager();
Animal<?, ?> animal = AnimalRP.users.get(player.getUniqueId());
if(animal == null) return;
if(animal.name != this.name) return;
if(event.getCause() == DamageCause.ENTITY_ATTACK && event.getEntity().getType() != EntityType.PLAYER) {
event.setDamage(event.getDamage()*1.25);
}
}
}
@Override
public String chatTransformations(String message) {
return this.destroyer.destroy(message);
}
}

View file

@ -0,0 +1,40 @@
package ovh.sad.animalrp.paper.listeners;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import io.papermc.paper.event.player.AsyncChatEvent;
import ovh.sad.animalrp.common.util.Animal;
import ovh.sad.animalrp.common.util.Mood;
import ovh.sad.animalrp.paper.AnimalRPPaper;
public abstract class PlayerChat implements Listener {
Random random = new Random();
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(final AsyncChatEvent event) {
Player player = event.getPlayer();
if (AnimalRPPaper.noChat.get(player.getUniqueId()) != null)
return;
@SuppressWarnings("unchecked")
Animal<Sound, Material> animal = (Animal<Sound, Material>) AnimalRPPaper.users.get(player.getUuid());
if (animal == null)
return;
if (random.nextDouble() < 0.08) {
player.getWorld().playSound(player.getLocation(),
animal.moodSounds.get(Mood.HAPPY), SoundCategory.PLAYERS, 10F, 1);
}
event.message()
return original
.withUnsignedContent(Text.literal(animal.chatTransformations(original.getContent().getString())));
}
}