implement dog + fix sex

This commit is contained in:
yourfriendoss 2024-03-31 22:05:37 +03:00
parent 8eb328b0f7
commit 2604e8f4dc
6 changed files with 156 additions and 89 deletions

View file

@ -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,6 +198,7 @@ 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());

View file

@ -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*",

View file

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

View file

@ -29,52 +29,7 @@ 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 {
@ -87,10 +42,10 @@ public class SexCommand implements CommandExecutor {
public void run() {
Set<Entry<UUID, SexModel>> modelset = models.entrySet();
for (Iterator<Entry<UUID, SexModel>> iterator = modelset.iterator(); iterator.hasNext(); ) {
for (Iterator<Entry<UUID, SexModel>> iterator = modelset.iterator(); iterator.hasNext();) {
Entry<UUID, SexModel> 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 {
@ -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("<gray>I'm sorry console. :(</gray>"));
return true;
}
Player player = (Player)arg0;
Player player = (Player) arg0;
if(!player.isOp()) {
if (!player.isOp()) {
arg0.sendMessage(AnimalRP.mm.deserialize("<red>You are not an OP!"));
return true;
}
if(arg3.length == 0) {
if (arg3.length == 0) {
arg0.sendMessage(AnimalRP.mm.deserialize("<red>Include player!"));
return true;
}
String playerName = arg3[0];
OfflinePlayer of = Bukkit.getOfflinePlayer(playerName);
if(of == null) {
if (of == null) {
arg0.sendMessage(AnimalRP.mm.deserialize("<red>User has never joined."));
return true;
}
if(SexCommand.models.containsKey(player.getUniqueId())) {
if (SexCommand.models.containsKey(player.getUniqueId())) {
arg0.sendMessage(AnimalRP.mm.deserialize("<red>You are already in progress."));
return true;
}
@ -228,4 +184,54 @@ public class SexCommand implements CommandExecutor {
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();
}
}
}

View file

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

View file

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