API for updating recipes on clients

This commit is contained in:
Jake Potrebic 2021-08-21 17:25:38 -07:00
parent 4c98f21716
commit 06b00246a2
2 changed files with 62 additions and 13 deletions

View File

@ -596,10 +596,11 @@
}
- return ichatmutablecomponent;
- } else {
- return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(profile) ? Component.translatable("multiplayer.disconnect.server_full") : null;
+ // return chatmessage;
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
} else {
- return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(profile) ? Component.translatable("multiplayer.disconnect.server_full") : null;
+ } else {
+ // return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null;
+ if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) {
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure
@ -863,10 +864,11 @@
this.sendAllPlayerInfoIn = 0;
}
@@ -541,6 +952,25 @@
@@ -540,6 +951,25 @@
}
}
+
+ // CraftBukkit start - add a world/entity limited version
+ public void broadcastAll(Packet packet, net.minecraft.world.entity.player.Player entityhuman) {
+ for (int i = 0; i < this.players.size(); ++i) {
@ -885,10 +887,9 @@
+
+ }
+ // CraftBukkit end
+
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
Iterator iterator = this.players.iterator();
@@ -554,7 +984,7 @@
}
@ -928,7 +929,7 @@
if (player.connection != null) {
byte b0;
@@ -643,36 +1078,53 @@
@@ -643,35 +1078,52 @@
player.connection.send(new ClientboundEntityEventPacket(player, b0));
}
@ -985,16 +986,15 @@
+ public void broadcast(@Nullable net.minecraft.world.entity.player.Player player, double x, double y, double z, double distance, ResourceKey<Level> worldKey, Packet<?> packet) {
for (int i = 0; i < this.players.size(); ++i) {
ServerPlayer entityplayer = (ServerPlayer) this.players.get(i);
+
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet
+ if (player != null && !entityplayer.getBukkitEntity().canSee(player.getBukkitEntity())) {
+ continue;
+ }
+ // CraftBukkit end
+
if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
double d4 = x - entityplayer.getX();
double d5 = y - entityplayer.getY();
@@ -687,10 +1139,12 @@
}
@ -1202,11 +1202,18 @@
}
advancementdataplayer.setPlayer(player);
@@ -932,15 +1449,28 @@
@@ -932,15 +1449,39 @@
}
public void reloadResources() {
- Iterator iterator = this.advancements.values().iterator();
+ // Paper start - API for updating recipes on clients
+ this.reloadAdvancementData();
+ this.reloadTagData();
+ this.reloadRecipes();
+ }
+ public void reloadAdvancementData() {
+ // Paper end - API for updating recipes on clients
+ // CraftBukkit start
+ /*Iterator iterator = this.advancements.values().iterator();
@ -1223,9 +1230,13 @@
}
+ // CraftBukkit end
+ // Paper start - API for updating recipes on clients
+ }
+ public void reloadTagData() {
this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries)));
+ // CraftBukkit start
+ this.reloadRecipes();
+ // this.reloadRecipes(); // Paper - do not reload recipes just because tag data was reloaded
+ // Paper end - API for updating recipes on clients
+ }
+
+ public void reloadRecipes() {

View File

@ -1190,6 +1190,18 @@ public final class CraftServer implements Server {
ReloadCommand.reload(this.console);
}
// Paper start - API for updating recipes on clients
@Override
public void updateResources() {
this.playerList.reloadResources();
}
@Override
public void updateRecipes() {
this.playerList.reloadRecipes();
}
// Paper end - API for updating recipes on clients
private void loadIcon() {
this.icon = new CraftIconCache(null);
try {
@ -1569,6 +1581,13 @@ public final class CraftServer implements Server {
@Override
public boolean addRecipe(Recipe recipe) {
// Paper start - API for updating recipes on clients
return this.addRecipe(recipe, false);
}
@Override
public boolean addRecipe(Recipe recipe, boolean resendRecipes) {
// Paper end - API for updating recipes on clients
CraftRecipe toAdd;
if (recipe instanceof CraftRecipe) {
toAdd = (CraftRecipe) recipe;
@ -1600,6 +1619,11 @@ public final class CraftServer implements Server {
}
}
toAdd.addToCraftingManager();
// Paper start - API for updating recipes on clients
if (true || resendRecipes) { // Always needs to be resent now... TODO
this.playerList.reloadRecipes();
}
// Paper end - API for updating recipes on clients
return true;
}
@ -1780,9 +1804,23 @@ public final class CraftServer implements Server {
@Override
public boolean removeRecipe(NamespacedKey recipeKey) {
// Paper start - API for updating recipes on clients
return this.removeRecipe(recipeKey, false);
}
@Override
public boolean removeRecipe(NamespacedKey recipeKey, boolean resendRecipes) {
// Paper end - API for updating recipes on clients
Preconditions.checkArgument(recipeKey != null, "recipeKey == null");
return this.getServer().getRecipeManager().removeRecipe(CraftRecipe.toMinecraft(recipeKey));
// Paper start - resend recipes on successful removal
final ResourceKey<net.minecraft.world.item.crafting.Recipe<?>> minecraftKey = CraftRecipe.toMinecraft(recipeKey);
final boolean removed = this.getServer().getRecipeManager().removeRecipe(minecraftKey);
if (removed/* && resendRecipes*/) { // TODO Always need to resend them rn - deprecate this method?
this.playerList.reloadRecipes();
}
return removed;
// Paper end - resend recipes on successful removal
}
@Override