Skip to content

Commit e258050

Browse files
authored
Merge pull request #1 from FrankTCA/1.21.7
Merge 1.21.7 work into main
2 parents 70f0d1a + b674995 commit e258050

File tree

14 files changed

+196
-74
lines changed

14 files changed

+196
-74
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'org.infotoast'
8-
version = '3.0'
8+
version = '3.1'
99

1010
repositories {
1111
mavenCentral()
@@ -21,7 +21,7 @@ repositories {
2121
}
2222

2323
dependencies {
24-
paperweight.paperDevBundle("1.21.5-R0.1-SNAPSHOT")
24+
paperweight.paperDevBundle("1.21.7-R0.1-SNAPSHOT")
2525
}
2626

2727
def targetJavaVersion = 21
@@ -52,7 +52,7 @@ processResources {
5252
}
5353

5454
runServer {
55-
minecraftVersion("1.21.5")
55+
minecraftVersion("1.21.7")
5656
}
5757

5858
tasks.assemble {

src/main/java/org/infotoast/petcontrol/PetControl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void onEnable() {
3131
getCommand("transferpetowner").setExecutor(new TransferPetOwnerCommand(this));
3232
getCommand("healpet").setExecutor(new HealPetCommand(this));
3333
getCommand("roam").setExecutor(new RoamCommand(this));
34+
getCommand("follow").setExecutor(new FollowCommand(this));
3435
this.cacheManager = new CacheFileManager(this);
3536
this.cacheManager.onStartup();
3637
getServer().getPluginManager().registerEvents(new PetListener(), this);

src/main/java/org/infotoast/petcontrol/PetListener.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@ public class PetListener implements Listener {
1818
@EventHandler(priority=EventPriority.MONITOR)
1919
public void onChunkLoad(ChunkLoadEvent event) {
2020
if (!entityAddLock) {
21-
for (org.bukkit.entity.Entity entity : event.getChunk().getEntities())
22-
if (entity.getType().equals(EntityType.CAT) || entity.getType().equals(EntityType.WOLF)) {
21+
for (org.bukkit.entity.Entity entity : event.getChunk().getEntities()) {
22+
//if (entity instanceof CraftCat || entity instanceof CraftWolf) {
2323
RoamingAnimalEntry ent = PetControl.cacheManager.checkIfRoamingAnimalFromUUID(entity.getUniqueId());
2424
if (ent != null) {
25-
//BukkitScheduler scheduler = PetControl.plugin.getServer().getScheduler();
26-
//scheduler.scheduleSyncDelayedTask(PetControl.plugin, () -> {
27-
if (ent.getAnimal().equals(RoamingAnimal.CAT)) {
28-
RoamingCat rcat = RoamingCat.convertFromCat(((CraftCat)entity).getHandle(),
29-
ent.getCenterX(), ent.getCenterZ(), ent.getRadius(), ent.isGuarded());
30-
} else {
31-
RoamingDog rdog = RoamingDog.convertFromWolf(((CraftWolf)entity).getHandle(),
32-
ent.getCenterX(), ent.getCenterZ(), ent.getRadius(), ent.isGuarded());
33-
}
34-
//}, 5L);
25+
if (ent.getAnimal().equals(RoamingAnimal.CAT)) {
26+
RoamingCat rcat = RoamingCat.convertFromCat(((CraftCat) entity).getHandle(),
27+
ent.getCenterX(), ent.getCenterZ(), ent.getRadius(), ent.isGuarded());
28+
} else {
29+
RoamingDog rdog = RoamingDog.convertFromWolf(((CraftWolf) entity).getHandle(),
30+
ent.getCenterX(), ent.getCenterZ(), ent.getRadius(), ent.isGuarded());
31+
}
3532
}
33+
//}
3634
}
3735
}
3836
}

src/main/java/org/infotoast/petcontrol/cachefile/RoamingAnimalEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ public static RoamingAnimalEntry readBytes(byte[] bytes) {
113113

114114
@Override
115115
public String toString() {
116-
return "RoamingAnimal " + convertIdToAnimal(animalId) + " center: " + centerX + ", " + centerZ + " radius: " + radius;
116+
return "RoamingAnimal " + convertIdToAnimal(animalId) + " center: " + centerX + ", " + centerZ + " radius: " + radius + " uuid: " + uuid + " guarded: " + guarded;
117117
}
118118
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.infotoast.petcontrol.command;
2+
3+
import net.minecraft.world.entity.TamableAnimal;
4+
import net.minecraft.world.entity.animal.Cat;
5+
import net.minecraft.world.entity.animal.wolf.Wolf;
6+
import org.bukkit.command.Command;
7+
import org.bukkit.command.CommandExecutor;
8+
import org.bukkit.command.CommandSender;
9+
import org.bukkit.craftbukkit.entity.CraftEntity;
10+
import org.bukkit.entity.Entity;
11+
import org.bukkit.entity.Player;
12+
import org.infotoast.petcontrol.PetControl;
13+
import org.infotoast.petcontrol.customanimals.RoamingCat;
14+
import org.infotoast.petcontrol.customanimals.RoamingDog;
15+
16+
import java.util.Objects;
17+
import java.util.UUID;
18+
19+
public class FollowCommand implements CommandExecutor {
20+
private final PetControl plugin;
21+
public FollowCommand(PetControl plugin) {
22+
this.plugin = plugin;
23+
}
24+
25+
@Override
26+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
27+
if (sender instanceof Player) {
28+
if (sender.hasPermission("petcontrol.follow")) {
29+
Player player = (Player) sender;
30+
Entity playerFacing = PetControl.getPlayerFacingEntity(player);
31+
if (playerFacing != null) {
32+
CraftEntity craftPlayerFacing = (CraftEntity)playerFacing;
33+
net.minecraft.world.entity.Entity animalFacing = craftPlayerFacing.getHandle();
34+
if (animalFacing instanceof TamableAnimal) {
35+
TamableAnimal tamableAnimal = (TamableAnimal) animalFacing;
36+
if (tamableAnimal.isTame()) {
37+
UUID ownerUUID = Objects.requireNonNull(tamableAnimal.getOwnerReference()).getUUID();
38+
if (ownerUUID.equals(player.getUniqueId()) || sender.hasPermission("petcontrol.follow.others")) {
39+
if (tamableAnimal instanceof RoamingCat) {
40+
Cat newCat = ((RoamingCat) tamableAnimal).convertToCat();
41+
sender.sendMessage("§bCat is now reset to normal AI and will follow and teleport.");
42+
sender.sendMessage("§bUUID: " + newCat.getUUID());
43+
return true;
44+
} else if (tamableAnimal instanceof RoamingDog) {
45+
Wolf newWolf = ((RoamingDog) tamableAnimal).convertToWolf();
46+
sender.sendMessage("§bDog is now reset to normal AI and will follow and teleport.");
47+
sender.sendMessage("§bUUID: " + newWolf.getUUID());
48+
return true;
49+
} else {
50+
sender.sendMessage("§4You must face a cat or dog that is roaming.");
51+
return false;
52+
}
53+
} else {
54+
sender.sendMessage("§4You do not have permission to make set other's animals to follow mode.");
55+
return false;
56+
}
57+
} else {
58+
sender.sendMessage("§4This command only works for tamed animals.");
59+
return false;
60+
}
61+
} else {
62+
sender.sendMessage("§4You must face a tamable animal.");
63+
return false;
64+
}
65+
} else {
66+
sender.sendMessage("§4You must face an animal.");
67+
return false;
68+
}
69+
} else {
70+
sender.sendMessage("§4You do not have permission to use this command!");
71+
return true;
72+
}
73+
} else {
74+
sender.sendMessage("Only players can use this command!");
75+
return false;
76+
}
77+
}
78+
}

src/main/java/org/infotoast/petcontrol/command/HealPetCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
3636
return false;
3737
}
3838
sender.sendMessage("§4Access denied.");
39-
return false;
39+
return true;
4040
}
4141
sender.sendMessage("§4You must be a player to use this command!");
4242
return false;

src/main/java/org/infotoast/petcontrol/command/PetInfoCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
6464
return false;
6565
}
6666
sender.sendMessage("§4Access denied.");
67-
return false;
67+
return true;
6868
}
6969
sender.sendMessage("§4This command must be sent by a player!");
7070
return false;

src/main/java/org/infotoast/petcontrol/command/RoamCommand.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
7474
}
7575
}
7676

77-
78-
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
79-
scheduler.scheduleSyncDelayedTask(plugin, () -> PetListener.entityAddLock = false, 3L);
80-
8177
if (ownerUUID.equals(player.getUniqueId()) || sender.hasPermission("petcontrol.roam.others")) {
8278
if (tamableAnimal instanceof Cat) {
8379
playerFacing.remove();
@@ -113,7 +109,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
113109
}
114110
} else {
115111
sender.sendMessage("§4You do not have permission to use this command.");
116-
return false;
112+
return true;
117113
}
118114
} else {
119115
sender.sendMessage("Command must be run as a player.");

src/main/java/org/infotoast/petcontrol/command/TamePetCommand.java

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package org.infotoast.petcontrol.command;
22

3-
import net.minecraft.world.entity.TamableAnimal;
43
import org.bukkit.Bukkit;
4+
import org.bukkit.OfflinePlayer;
55
import org.bukkit.command.Command;
66
import org.bukkit.command.CommandExecutor;
77
import org.bukkit.command.CommandSender;
8-
import org.bukkit.craftbukkit.entity.CraftEntity;
9-
import org.bukkit.craftbukkit.entity.CraftPlayer;
108
import org.bukkit.entity.Entity;
119
import org.bukkit.entity.Player;
1210

11+
import org.bukkit.entity.Tameable;
1312
import org.infotoast.petcontrol.PetControl;
1413

15-
import java.util.logging.Level;
16-
1714
public class TamePetCommand implements CommandExecutor {
1815
private final PetControl plugin;
1916

@@ -28,28 +25,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
2825
Player player = (Player) sender;
2926
Entity playerFacing = PetControl.getPlayerFacingEntity(player);
3027
if (playerFacing != null) {
31-
CraftEntity craftPlayerFacing = (CraftEntity)playerFacing;
32-
net.minecraft.world.entity.Entity animalFacing = craftPlayerFacing.getHandle();
33-
if (animalFacing instanceof TamableAnimal) {
34-
TamableAnimal tamableAnimal = (TamableAnimal) animalFacing;
35-
if (!tamableAnimal.isTame()) {
36-
net.minecraft.world.entity.player.Player newOwner;
28+
if (playerFacing instanceof Tameable) {
29+
Tameable tamableAnimal = (Tameable) playerFacing;
30+
if (!tamableAnimal.isTamed()) {
31+
OfflinePlayer newOwner;
3732
if (args.length == 1) {
3833
if (sender.hasPermission("petcontrol.tamepet.others")) {
3934
String nextOwnerName = args[0];
40-
CraftPlayer craftPlayer = (CraftPlayer) Bukkit.getPlayer(nextOwnerName);
41-
if (craftPlayer != null) {
42-
net.minecraft.world.entity.Entity thePlayerEntity = craftPlayer.getHandleRaw();
43-
if (thePlayerEntity instanceof net.minecraft.world.entity.player.Player) {
44-
newOwner = (net.minecraft.world.entity.player.Player) thePlayerEntity;
45-
} else {
46-
plugin.logger.log(Level.SEVERE, "Assert net.minecraft.world.entity.player.Player");
47-
sender.sendMessage("§4Something went wrong! Check console for more info.");
48-
return false;
49-
}
50-
} else {
51-
plugin.logger.log(Level.SEVERE, "Assert craftPlayer is not null");
52-
sender.sendMessage("§4Something went wrong! Check console for more info.");
35+
newOwner = Bukkit.getOfflinePlayer(nextOwnerName);
36+
if (!newOwner.hasPlayedBefore()) {
37+
sender.sendMessage("§4Player either does not exist or has not played before!");
5338
return false;
5439
}
5540
} else {
@@ -58,14 +43,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
5843
}
5944
} else if (args.length == 0) {
6045
if (sender.hasPermission("petcontrol.tamepet.self")) {
61-
net.minecraft.world.entity.Entity thePlayerEntity = ((CraftPlayer)player).getHandleRaw();
62-
if (thePlayerEntity instanceof net.minecraft.world.entity.player.Player) {
63-
newOwner = (net.minecraft.world.entity.player.Player) thePlayerEntity;
64-
} else {
65-
plugin.logger.log(Level.SEVERE, "Assert playerEntity instance of net.minecraft.world.entity.player.Player");
66-
sender.sendMessage("§4Something went wrong! Check console for more info.");
67-
return false;
68-
}
46+
newOwner = (Player)sender;
6947
} else {
7048
sender.sendMessage("§4You do not have permission to tame pets for yourself.");
7149
return false;
@@ -74,7 +52,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
7452
sender.sendMessage("§4Too many arguments. Command usage: tamepet <Player>.");
7553
return false;
7654
}
77-
tamableAnimal.tame(newOwner);
55+
tamableAnimal.setOwner(newOwner);
7856
sender.sendMessage("§bAnimal has been tamed!");
7957
return true;
8058
}
@@ -88,7 +66,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
8866
return false;
8967
}
9068
sender.sendMessage("§4Access denied.");
91-
return false;
69+
return true;
9270
}
9371
sender.sendMessage("§4This command must be sent by a player!");
9472
return false;

src/main/java/org/infotoast/petcontrol/command/ToggleSitCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
4141
return false;
4242
}
4343
sender.sendMessage("§4Access denied.");
44-
return false;
44+
return true;
4545
}
4646
sender.sendMessage("§4This command must be sent by a player!");
4747
return false;

0 commit comments

Comments
 (0)