From 2604e8f4dcfb9d49bda91d890ab9eb5b2b83b18f Mon Sep 17 00:00:00 2001 From: yourfriendoss <81387799+yourfriendoss@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:05:37 +0300 Subject: [PATCH] implement dog + fix sex --- src/main/java/lv/pi/animalrp/AnimalRP.java | 6 +- src/main/java/lv/pi/animalrp/animals/Bee.java | 13 -- src/main/java/lv/pi/animalrp/animals/Dog.java | 54 +++++++ .../lv/pi/animalrp/commands/SexCommand.java | 146 +++++++++--------- .../lv/pi/animalrp/listeners/PlayerChat.java | 7 +- .../lv/pi/animalrp/listeners/PlayerLeave.java | 19 +++ 6 files changed, 156 insertions(+), 89 deletions(-) create mode 100644 src/main/java/lv/pi/animalrp/animals/Dog.java create mode 100644 src/main/java/lv/pi/animalrp/listeners/PlayerLeave.java diff --git a/src/main/java/lv/pi/animalrp/AnimalRP.java b/src/main/java/lv/pi/animalrp/AnimalRP.java index 6a14516..3bbe324 100644 --- a/src/main/java/lv/pi/animalrp/AnimalRP.java +++ b/src/main/java/lv/pi/animalrp/AnimalRP.java @@ -49,6 +49,7 @@ import com.google.gson.JsonSyntaxException; import lv.pi.animalrp.animals.Animal; import lv.pi.animalrp.animals.Bee; import lv.pi.animalrp.animals.Cat; +import lv.pi.animalrp.animals.Dog; import lv.pi.animalrp.animals.Fox; import lv.pi.animalrp.commands.EmoteCommand; import lv.pi.animalrp.commands.InteractionCommand; @@ -57,6 +58,7 @@ import lv.pi.animalrp.commands.ClearCooldownCommand; import lv.pi.animalrp.commands.SexCommand; import lv.pi.animalrp.commands.TfCommand; import lv.pi.animalrp.listeners.PlayerChat; +import lv.pi.animalrp.listeners.PlayerLeave; import lv.pi.animalrp.util.Cooldown; import lv.pi.animalrp.util.Emote; import lv.pi.animalrp.util.Mood; @@ -142,6 +144,7 @@ public class AnimalRP extends JavaPlugin { animals.put("cat", new Cat()); animals.put("fox", new Fox()); + animals.put("dog", new Dog()); animals.put("bee", new Bee()); animals.forEach((z,b) -> { @@ -195,7 +198,8 @@ public class AnimalRP extends JavaPlugin { } pm.registerEvents(new PlayerChat(), this); - + pm.registerEvents(new PlayerLeave(), this); + getCommand("tf").setExecutor(new TfCommand()); getCommand("emote").setExecutor(new EmoteCommand()); getCommand("sex").setExecutor(new SexCommand()); diff --git a/src/main/java/lv/pi/animalrp/animals/Bee.java b/src/main/java/lv/pi/animalrp/animals/Bee.java index 3677529..bd770e3 100644 --- a/src/main/java/lv/pi/animalrp/animals/Bee.java +++ b/src/main/java/lv/pi/animalrp/animals/Bee.java @@ -17,19 +17,6 @@ import lv.pi.animalrp.AnimalRP; import lv.pi.animalrp.util.Mood; import lv.pi.animalrp.util.TextDestroyer; -class Cooldown { - Integer duration; - Long executionTime; - public Cooldown(Integer duration, Long executionTime) { - this.duration = duration; - this.executionTime = executionTime; - } - - public boolean isExpired() { - return this.executionTime-(System.currentTimeMillis()-this.duration) <= 0; - } -} - public class Bee extends Animal { TextDestroyer destroyer = new TextDestroyer(new String[]{ ">_<", "*buzz*", diff --git a/src/main/java/lv/pi/animalrp/animals/Dog.java b/src/main/java/lv/pi/animalrp/animals/Dog.java new file mode 100644 index 0000000..627a46e --- /dev/null +++ b/src/main/java/lv/pi/animalrp/animals/Dog.java @@ -0,0 +1,54 @@ +package lv.pi.animalrp.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 lv.pi.animalrp.AnimalRP; +import lv.pi.animalrp.util.Mood; +import lv.pi.animalrp.util.TextDestroyer; + + +public class Dog extends Animal { + 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 = AnimalRP.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); + } +} \ No newline at end of file diff --git a/src/main/java/lv/pi/animalrp/commands/SexCommand.java b/src/main/java/lv/pi/animalrp/commands/SexCommand.java index 94087e2..7068ec0 100644 --- a/src/main/java/lv/pi/animalrp/commands/SexCommand.java +++ b/src/main/java/lv/pi/animalrp/commands/SexCommand.java @@ -29,68 +29,23 @@ import org.jetbrains.annotations.NotNull; import lv.pi.animalrp.AnimalRP; enum Yaw { - NORTH,EAST,WEST,SOUTH; -} - -class SexModel { - ArmorStand as; - Yaw yaw; - int sexTicks = 0; - boolean finished = false; - Location playerLocation; - - public SexModel(ArmorStand as, Yaw yaw, Location playerLocation) { - this.as = as; this.yaw = yaw; this.playerLocation = playerLocation; - } - - public void tickSex(Player player) { - player.teleport(this.playerLocation); - - this.sexTicks ++; - if(this.sexTicks %2 == 0) { - Yaw opposite = Yaw.NORTH; - if(this.yaw == Yaw.NORTH) opposite = Yaw.SOUTH; - if(this.yaw == Yaw.WEST) opposite = Yaw.EAST; - if(this.yaw == Yaw.EAST) opposite = Yaw.WEST; - if(this.yaw == Yaw.SOUTH) opposite = Yaw.NORTH; - this.yaw = opposite; - Location asl = this.as.getLocation(); - asl.add(SexCommand.getVector(this.yaw, 0.2)); - as.teleport(asl); - } - - if(this.sexTicks == 30) { - player.sendMessage(AnimalRP.mm.deserialize("<#FFC0CB>I'm about to..")); - } - - if(this.sexTicks == 50) { - player.sendMessage(AnimalRP.mm.deserialize("<#FFC0CB>cum!!")); - player.getWorld().spawnParticle(Particle.END_ROD, player.getLocation(), 999, 0, 0, 0); - this.removeModel(); - finished = true; - } - } - - - public void removeModel() { - this.as.remove(); - } + NORTH, EAST, WEST, SOUTH; } public class SexCommand implements CommandExecutor { static public HashMap models = new HashMap(); - + public SexCommand() { Bukkit.getScheduler().scheduleSyncRepeatingTask(AnimalRP.getProvidingPlugin(AnimalRP.class), new Runnable() { @Override public void run() { Set> modelset = models.entrySet(); - for (Iterator> iterator = modelset.iterator(); iterator.hasNext(); ) { + for (Iterator> iterator = modelset.iterator(); iterator.hasNext();) { Entry value = iterator.next(); Player plr = Bukkit.getPlayer(value.getKey()); - if(plr == null || value.getValue().finished) { + if (plr == null || value.getValue().finished) { value.getValue().removeModel(); iterator.remove(); } else { @@ -100,7 +55,7 @@ public class SexCommand implements CommandExecutor { } }, 5, 5); } - + public static Location faceLocation(Entity entity, Location to) { if (entity.getWorld() != to.getWorld()) { return null; @@ -147,52 +102,53 @@ public class SexCommand implements CommandExecutor { } public static Vector getVector(Yaw yaw, Double amount) { - if(yaw == Yaw.NORTH) { + if (yaw == Yaw.NORTH) { return new Vector(0, 0, -amount); } - - if(yaw == Yaw.SOUTH) { + + if (yaw == Yaw.SOUTH) { return new Vector(0, 0, amount); } - - if(yaw == Yaw.EAST) { + + if (yaw == Yaw.EAST) { return new Vector(amount, 0, 0); } - - if(yaw == Yaw.WEST) { + + if (yaw == Yaw.WEST) { return new Vector(-amount, 0, 0); } - - return new Vector(0, 0,0); + + return new Vector(0, 0, 0); } @Override - public boolean onCommand(@NotNull CommandSender arg0, @NotNull Command arg1, @NotNull String arg2, @NotNull String[] arg3) { - if(!(arg0 instanceof Player)) { + public boolean onCommand(@NotNull CommandSender arg0, @NotNull Command arg1, @NotNull String arg2, + @NotNull String[] arg3) { + if (!(arg0 instanceof Player)) { arg0.sendMessage(AnimalRP.mm.deserialize("I'm sorry console. :(")); return true; } - - Player player = (Player)arg0; - if(!player.isOp()) { + Player player = (Player) arg0; + + if (!player.isOp()) { arg0.sendMessage(AnimalRP.mm.deserialize("You are not an OP!")); return true; } - if(arg3.length == 0) { + if (arg3.length == 0) { arg0.sendMessage(AnimalRP.mm.deserialize("Include player!")); return true; } String playerName = arg3[0]; OfflinePlayer of = Bukkit.getOfflinePlayer(playerName); - if(of == null) { + if (of == null) { arg0.sendMessage(AnimalRP.mm.deserialize("User has never joined.")); return true; } - - if(SexCommand.models.containsKey(player.getUniqueId())) { + + if (SexCommand.models.containsKey(player.getUniqueId())) { arg0.sendMessage(AnimalRP.mm.deserialize("You are already in progress.")); return true; } @@ -213,7 +169,7 @@ public class SexCommand implements CommandExecutor { as.setGravity(false); as.setHeadPose(new EulerAngle(0.15, 0, 0)); as.setInvulnerable(true); - + as.addEquipmentLock(EquipmentSlot.HEAD, LockType.ADDING); as.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING); as.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING); @@ -227,5 +183,55 @@ public class SexCommand implements CommandExecutor { SexCommand.models.put(player.getUniqueId(), new SexModel(as, yaw, player.getLocation())); return true; } - + + public class SexModel { + ArmorStand as; + Yaw yaw; + int sexTicks = 0; + boolean finished = false; + Location playerLocation; + + public SexModel(ArmorStand as, Yaw yaw, Location playerLocation) { + this.as = as; + this.yaw = yaw; + this.playerLocation = playerLocation; + } + + public void tickSex(Player player) { + player.teleport(this.playerLocation); + + this.sexTicks++; + if (this.sexTicks % 2 == 0) { + Yaw opposite = Yaw.NORTH; + if (this.yaw == Yaw.NORTH) + opposite = Yaw.SOUTH; + if (this.yaw == Yaw.WEST) + opposite = Yaw.EAST; + if (this.yaw == Yaw.EAST) + opposite = Yaw.WEST; + if (this.yaw == Yaw.SOUTH) + opposite = Yaw.NORTH; + this.yaw = opposite; + Location asl = this.as.getLocation(); + asl.add(SexCommand.getVector(this.yaw, 0.2)); + as.teleport(asl); + } + + if (this.sexTicks == 30) { + player.sendMessage(AnimalRP.mm.deserialize("<#FFC0CB>I'm about to..")); + } + + if (this.sexTicks == 50) { + player.sendMessage(AnimalRP.mm.deserialize("<#FFC0CB>cum!!")); + player.getWorld().spawnParticle(Particle.END_ROD, player.getLocation(), 999, 0, 0, 0); + this.removeModel(); + finished = true; + } + } + + public void removeModel() { + this.as.remove(); + } + } + } \ 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 c8ecbae..37f89d4 100644 --- a/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java +++ b/src/main/java/lv/pi/animalrp/listeners/PlayerChat.java @@ -97,11 +97,8 @@ public class PlayerChat implements Listener { cprefix = Component.text(prefix); } } - if(chatModOff) { - event.renderer(new CustomChatRenderer(null, team, csuffix, cprefix)); - } else { - event.renderer(new CustomChatRenderer(animal, team, csuffix, cprefix)); - } + + event.renderer(new CustomChatRenderer(chatModOff ? null : animal, team, csuffix, cprefix)); } } diff --git a/src/main/java/lv/pi/animalrp/listeners/PlayerLeave.java b/src/main/java/lv/pi/animalrp/listeners/PlayerLeave.java new file mode 100644 index 0000000..581cad3 --- /dev/null +++ b/src/main/java/lv/pi/animalrp/listeners/PlayerLeave.java @@ -0,0 +1,19 @@ +package lv.pi.animalrp.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import lv.pi.animalrp.commands.SexCommand; +import lv.pi.animalrp.commands.SexCommand.SexModel; + +public class PlayerLeave implements Listener { + @EventHandler + public void onLeavePlayer(PlayerQuitEvent event) { + SexModel model = SexCommand.models.get(event.getPlayer().getUniqueId()); + if(model != null) { + model.removeModel(); + SexCommand.models.remove(event.getPlayer().getUniqueId()); + } + } +}